2022-06-29 19:46:41 -04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2023-10-27 03:38:29 +10:00
|
|
|
|
using Bit.Core.AdminConsole.Entities.Provider;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Models.Data.Provider;
|
2024-04-05 15:50:28 +01:00
|
|
|
|
using Bit.Core.Billing.Entities;
|
|
|
|
|
|
using Bit.Core.Enums;
|
2021-06-03 18:58:29 +02:00
|
|
|
|
|
2024-02-21 09:18:09 +10:00
|
|
|
|
namespace Bit.Admin.AdminConsole.Models;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2021-06-03 18:58:29 +02:00
|
|
|
|
public class ProviderEditModel : ProviderViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
public ProviderEditModel() { }
|
|
|
|
|
|
|
2024-04-05 15:50:28 +01:00
|
|
|
|
public ProviderEditModel(Provider provider, IEnumerable<ProviderUserUserDetails> providerUsers,
|
|
|
|
|
|
IEnumerable<ProviderOrganizationOrganizationDetails> organizations, IEnumerable<ProviderPlan> providerPlans)
|
2021-08-10 12:28:00 -04:00
|
|
|
|
: base(provider, providerUsers, organizations)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2024-03-05 10:56:48 +00:00
|
|
|
|
Name = provider.DisplayName();
|
|
|
|
|
|
BusinessName = provider.DisplayBusinessName();
|
2021-06-03 18:58:29 +02:00
|
|
|
|
BillingEmail = provider.BillingEmail;
|
2023-04-14 11:13:16 +01:00
|
|
|
|
BillingPhone = provider.BillingPhone;
|
2024-04-05 15:50:28 +01:00
|
|
|
|
TeamsMinimumSeats = GetMinimumSeats(providerPlans, PlanType.TeamsMonthly);
|
|
|
|
|
|
EnterpriseMinimumSeats = GetMinimumSeats(providerPlans, PlanType.EnterpriseMonthly);
|
2021-06-03 18:58:29 +02:00
|
|
|
|
}
|
2021-08-10 12:28:00 -04:00
|
|
|
|
|
2021-08-02 14:19:26 -04:00
|
|
|
|
[Display(Name = "Billing Email")]
|
2021-06-03 18:58:29 +02:00
|
|
|
|
public string BillingEmail { get; set; }
|
2023-04-14 11:13:16 +01:00
|
|
|
|
[Display(Name = "Billing Phone Number")]
|
|
|
|
|
|
public string BillingPhone { get; set; }
|
2021-08-02 14:19:26 -04:00
|
|
|
|
[Display(Name = "Business Name")]
|
2021-06-03 18:58:29 +02:00
|
|
|
|
public string BusinessName { get; set; }
|
|
|
|
|
|
public string Name { get; set; }
|
2024-04-05 15:50:28 +01:00
|
|
|
|
[Display(Name = "Teams minimum seats")]
|
|
|
|
|
|
public int TeamsMinimumSeats { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Display(Name = "Enterprise minimum seats")]
|
|
|
|
|
|
public int EnterpriseMinimumSeats { get; set; }
|
2021-07-08 17:05:32 +02:00
|
|
|
|
[Display(Name = "Events")]
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2024-04-05 15:50:28 +01:00
|
|
|
|
public IEnumerable<ProviderPlan> ToProviderPlan(IEnumerable<ProviderPlan> existingProviderPlans)
|
|
|
|
|
|
{
|
|
|
|
|
|
var providerPlans = existingProviderPlans.ToList();
|
|
|
|
|
|
foreach (var existingProviderPlan in providerPlans)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingProviderPlan.SeatMinimum = existingProviderPlan.PlanType switch
|
|
|
|
|
|
{
|
|
|
|
|
|
PlanType.TeamsMonthly => TeamsMinimumSeats,
|
|
|
|
|
|
PlanType.EnterpriseMonthly => EnterpriseMinimumSeats,
|
|
|
|
|
|
_ => existingProviderPlan.SeatMinimum
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return providerPlans;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-08 17:05:32 +02:00
|
|
|
|
public Provider ToProvider(Provider existingProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingProvider.BillingEmail = BillingEmail?.ToLowerInvariant()?.Trim();
|
2023-04-14 11:13:16 +01:00
|
|
|
|
existingProvider.BillingPhone = BillingPhone?.ToLowerInvariant()?.Trim();
|
2021-07-08 17:05:32 +02:00
|
|
|
|
return existingProvider;
|
2021-06-03 18:58:29 +02:00
|
|
|
|
}
|
2024-04-05 15:50:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int GetMinimumSeats(IEnumerable<ProviderPlan> providerPlans, PlanType planType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (from providerPlan in providerPlans where providerPlan.PlanType == planType select (int)providerPlan.SeatMinimum).FirstOrDefault();
|
|
|
|
|
|
}
|
2021-06-03 18:58:29 +02:00
|
|
|
|
}
|