diff --git a/src/EventHub.Domain/Organizations/Plans/PlanInfoDefinition.cs b/src/EventHub.Domain/Organizations/Plans/PlanInfoDefinition.cs index eafc40f..459ceca 100644 --- a/src/EventHub.Domain/Organizations/Plans/PlanInfoDefinition.cs +++ b/src/EventHub.Domain/Organizations/Plans/PlanInfoDefinition.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Linq; using JetBrains.Annotations; +using Volo.Abp; namespace EventHub.Organizations.Plans; @@ -40,4 +42,31 @@ public class PlanInfoDefinition AdditionalFeatureInfos = new List() }; } + + public static bool IsValid(List definitions) + { + foreach (var definition in definitions) + { + var isValidPlanType = Enum.IsDefined(typeof(OrganizationPlanType), definition.PlanType); + if (!isValidPlanType) + { + return false; + } + + var isExistSamePlan = definitions.Count(x => x.Price == definition.Price && x.PlanType == definition.PlanType); + if (isExistSamePlan > 1) + { + return false; + } + + if (definition.IsActive && definition.IsExtendable) + { + Check.NotNull(definition.OnePaidEnrollmentPeriodAsMonth, nameof(definition.OnePaidEnrollmentPeriodAsMonth)); + Check.NotNull(definition.CanBeExtendedAfterHowManyMonths, nameof(definition.CanBeExtendedAfterHowManyMonths)); + return definition.OnePaidEnrollmentPeriodAsMonth > definition.CanBeExtendedAfterHowManyMonths; + } + } + + return true; + } } diff --git a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs index f1ed65e..8c167cd 100644 --- a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs +++ b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs @@ -6,7 +6,6 @@ using System.Linq; using EventHub.EntityFrameworkCore; using EventHub.Events; using EventHub.Organizations; -using EventHub.Organizations.PaymentRequests; using EventHub.Organizations.Plans; using EventHub.Utils; using EventHub.Web; @@ -201,33 +200,7 @@ namespace EventHub context.Services.AddOptions>() .Bind(configuration.GetSection(PlanInfoDefinition.PlanInfo)) .ValidateDataAnnotations() - .Validate(configOfDefinitions => - { - foreach (var config in configOfDefinitions) - { - var isValidPlanType = Enum.IsDefined(typeof(OrganizationPlanType), config.PlanType); - if (!isValidPlanType) - { - return false; - } - - var isExistSamePlan = configOfDefinitions.Count(x => - x.Price == config.Price && x.PlanType == config.PlanType); - if (isExistSamePlan > 1) - { - return false; - } - - if (config.IsActive && config.IsExtendable) - { - Check.NotNull(config.OnePaidEnrollmentPeriodAsMonth, nameof(config.OnePaidEnrollmentPeriodAsMonth)); - Check.NotNull(config.CanBeExtendedAfterHowManyMonths, nameof(config.CanBeExtendedAfterHowManyMonths)); - return config.OnePaidEnrollmentPeriodAsMonth > config.CanBeExtendedAfterHowManyMonths; - } - } - - return true; - }, "PlanInfoDefinition is not valid!"); + .Validate(PlanInfoDefinition.IsValid, "PlanInfoDefinition is not valid!"); var planInfos = context.Services.GetRequiredServiceLazy>>(); diff --git a/src/EventHub.Web/Pages/Organizations/PlanInfoHelper.cs b/src/EventHub.Web/Pages/Organizations/PlanInfoHelper.cs index 6e6d1e3..43623da 100644 --- a/src/EventHub.Web/Pages/Organizations/PlanInfoHelper.cs +++ b/src/EventHub.Web/Pages/Organizations/PlanInfoHelper.cs @@ -66,7 +66,7 @@ public static class PlanInfoHelper return productNameStringBuilder.ToString(); } - public static string GetRestrictionInfoByCount(uint? count) + public static string GetFeatureInfoByCount(uint? count) { count ??= uint.MaxValue; return count == uint.MaxValue ? "Unlimited" : count.ToString(); diff --git a/src/EventHub.Web/Pages/Pricing.cshtml b/src/EventHub.Web/Pages/Pricing.cshtml index ba7ccf2..687b433 100644 --- a/src/EventHub.Web/Pages/Pricing.cshtml +++ b/src/EventHub.Web/Pages/Pricing.cshtml @@ -25,9 +25,9 @@ @plan.Price
    -
  • @PlanInfoHelper.GetRestrictionInfoByCount(plan.Feature.MaxAllowedEventsCount) events in a year.
  • -
  • Up to @PlanInfoHelper.GetRestrictionInfoByCount(plan.Feature.MaxAllowedTracksCountInOneEvent).ToLower() tracks for an event.
  • -
  • Up to @PlanInfoHelper.GetRestrictionInfoByCount(plan.Feature.MaxAllowedAttendeesCountInOneEvent).ToLower() attendees per event.
  • +
  • @PlanInfoHelper.GetFeatureInfoByCount(plan.Feature.MaxAllowedEventsCount) events in a year.
  • +
  • Up to @PlanInfoHelper.GetFeatureInfoByCount(plan.Feature.MaxAllowedTracksCountInOneEvent).ToLower() tracks for an event.
  • +
  • Up to @PlanInfoHelper.GetFeatureInfoByCount(plan.Feature.MaxAllowedAttendeesCountInOneEvent).ToLower() attendees per event.
  • @foreach (var additionalFeatureInfo in plan.Feature.AdditionalFeatureInfos) {
  • @additionalFeatureInfo
  • diff --git a/src/EventHub.Web/Pages/Pricing.cshtml.cs b/src/EventHub.Web/Pages/Pricing.cshtml.cs index 056d07a..0c2cc74 100644 --- a/src/EventHub.Web/Pages/Pricing.cshtml.cs +++ b/src/EventHub.Web/Pages/Pricing.cshtml.cs @@ -21,7 +21,7 @@ namespace EventHub.Web.Pages [BindProperty] public OrganizationPlanType TargetPlanToUpgrade { get; set; } - [NotNull] + [ItemNotNull] public List PlanInfos { get; private set; } public OrganizationProfileDto Organization { get; private set; }