From f90c692c406331f9f8918a09be0a55a718eeb12a Mon Sep 17 00:00:00 2001 From: Cy Okeke Date: Thu, 22 May 2025 13:25:41 +0100 Subject: [PATCH] Resolve the repeated condition Signed-off-by: Cy Okeke --- .../Controllers/OrganizationsController.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Admin/AdminConsole/Controllers/OrganizationsController.cs b/src/Admin/AdminConsole/Controllers/OrganizationsController.cs index ad2e8b735b..0ec34fa3c2 100644 --- a/src/Admin/AdminConsole/Controllers/OrganizationsController.cs +++ b/src/Admin/AdminConsole/Controllers/OrganizationsController.cs @@ -258,27 +258,20 @@ public class OrganizationsController : Controller if (model.PlanType.HasValue) { var freePlan = await _pricingClient.GetPlanOrThrow(model.PlanType.Value); - - if (organization.PlanType != PlanType.Free && - model.PlanType.Value == PlanType.Free && - model.Seats.HasValue && - model.Seats.Value > freePlan.PasswordManager.MaxSeats) + var isDowngradingToFree = organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free; + switch (isDowngradingToFree) { - TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxSeats} seats cannot be downgraded to the Free plan"; - return RedirectToAction("Edit", new { id }); - } - - if (organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free && model.MaxCollections > freePlan.PasswordManager.MaxCollections) - { - TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxCollections} collections cannot be downgraded to the Free plan. Your organization currently has {organization.MaxCollections} collections."; - return RedirectToAction("Edit", new { id }); - } - - if (organization.PlanType != PlanType.Free && model.PlanType.Value == PlanType.Free) - { - model.MaxStorageGb = null; - model.ExpirationDate = null; - model.Enabled = true; + case true when model.Seats.HasValue && model.Seats.Value > freePlan.PasswordManager.MaxSeats: + TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxSeats} seats cannot be downgraded to the Free plan"; + return RedirectToAction("Edit", new { id }); + case true when model.MaxCollections > freePlan.PasswordManager.MaxCollections: + TempData["Error"] = $"Organizations with more than {freePlan.PasswordManager.MaxCollections} collections cannot be downgraded to the Free plan. Your organization currently has {organization.MaxCollections} collections."; + return RedirectToAction("Edit", new { id }); + case true: + model.MaxStorageGb = null; + model.ExpirationDate = null; + model.Enabled = true; + break; } }