From 3749fa61138ddfd84da1f9427d0f4ed74b2a14bd Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:20:48 +0100 Subject: [PATCH] resolve the issue (#4035) Signed-off-by: Cy Okeke --- .../Controllers/ProvidersController.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Admin/AdminConsole/Controllers/ProvidersController.cs b/src/Admin/AdminConsole/Controllers/ProvidersController.cs index bfb19e1cd5..0d3f7f996a 100644 --- a/src/Admin/AdminConsole/Controllers/ProvidersController.cs +++ b/src/Admin/AdminConsole/Controllers/ProvidersController.cs @@ -12,6 +12,7 @@ using Bit.Core.AdminConsole.Services; using Bit.Core.Billing.Entities; using Bit.Core.Billing.Extensions; using Bit.Core.Billing.Repositories; +using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Repositories; using Bit.Core.Services; @@ -195,9 +196,25 @@ public class ProvidersController : Controller } model.ToProviderPlan(providerPlans); - foreach (var providerPlan in providerPlans) + if (providerPlans.Count == 0) { - await _providerPlanRepository.ReplaceAsync(providerPlan); + var newProviderPlans = new List + { + new() {ProviderId = provider.Id, PlanType = PlanType.TeamsMonthly, SeatMinimum= model.TeamsMinimumSeats, PurchasedSeats = 0, AllocatedSeats = 0}, + new() {ProviderId = provider.Id, PlanType = PlanType.EnterpriseMonthly, SeatMinimum= model.EnterpriseMinimumSeats, PurchasedSeats = 0, AllocatedSeats = 0} + }; + + foreach (var newProviderPlan in newProviderPlans) + { + await _providerPlanRepository.CreateAsync(newProviderPlan); + } + } + else + { + foreach (var providerPlan in providerPlans) + { + await _providerPlanRepository.ReplaceAsync(providerPlan); + } } return RedirectToAction("Edit", new { id });