|
|
@ -2,60 +2,60 @@ using System; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using EventHub.Events; |
|
|
using EventHub.Events; |
|
|
using EventHub.Events.Registrations; |
|
|
using EventHub.Events.Registrations; |
|
|
|
|
|
using Microsoft.Extensions.Options; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.DependencyInjection; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
|
namespace EventHub.Organizations.Plans; |
|
|
namespace EventHub.Organizations.Plans; |
|
|
|
|
|
|
|
|
public class PlanFeatureManager : ITransientDependency |
|
|
public class PlanFeatureManager : ITransientDependency |
|
|
{ |
|
|
{ |
|
|
private readonly IPlanInfoDefinitionStore _planInfoDefinitionStore; |
|
|
private readonly IOptions<PlanInfoOptions> _planInfoOptions; |
|
|
private readonly IRepository<Organization, Guid> _organizationRepository; |
|
|
private readonly IRepository<Organization, Guid> _organizationRepository; |
|
|
private readonly IRepository<Event, Guid> _eventRepository; |
|
|
private readonly IRepository<Event, Guid> _eventRepository; |
|
|
private readonly IEventRegistrationRepository _eventRegistrationRepository; |
|
|
private readonly IEventRegistrationRepository _eventRegistrationRepository; |
|
|
|
|
|
private readonly IClock _clock; |
|
|
public PlanFeatureManager( |
|
|
public PlanFeatureManager( |
|
|
IPlanInfoDefinitionStore planInfoDefinitionStore, |
|
|
IOptions<PlanInfoOptions> planInfoOptions, |
|
|
IRepository<Organization, Guid> organizationRepository, |
|
|
IRepository<Organization, Guid> organizationRepository, |
|
|
IRepository<Event, Guid> eventRepository, |
|
|
IRepository<Event, Guid> eventRepository, |
|
|
IEventRegistrationRepository eventRegistrationRepository) |
|
|
IEventRegistrationRepository eventRegistrationRepository, |
|
|
|
|
|
IClock clock) |
|
|
{ |
|
|
{ |
|
|
_planInfoDefinitionStore = planInfoDefinitionStore; |
|
|
_planInfoOptions = planInfoOptions; |
|
|
_organizationRepository = organizationRepository; |
|
|
_organizationRepository = organizationRepository; |
|
|
_eventRepository = eventRepository; |
|
|
_eventRepository = eventRepository; |
|
|
_eventRegistrationRepository = eventRegistrationRepository; |
|
|
_eventRegistrationRepository = eventRegistrationRepository; |
|
|
|
|
|
_clock = clock; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual async Task<bool> CanCreateNewEvent(Guid organizationId) |
|
|
public virtual async Task<bool> CanCreateNewEventAsync(Guid organizationId) |
|
|
{ |
|
|
{ |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(organizationId); |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(organizationId); |
|
|
|
|
|
var totalEventCountByOrganizationInThisYear = await _eventRepository.CountAsync(x => x.OrganizationId == organizationId && x.CreationTime.Year == _clock.Now.Year); |
|
|
var totalEventCountByOrganization = await _eventRepository.CountAsync(x => x.OrganizationId == organizationId && x.CreationTime.Year < DateTime.Now.Year + 1 && x.CreationTime.Year > DateTime.Now.Year - 1); |
|
|
return currentPlanOfOrganization.Feature.MaxAllowedEventsCountInOneYear > totalEventCountByOrganizationInThisYear; |
|
|
totalEventCountByOrganization++; |
|
|
|
|
|
return currentPlanOfOrganization.Feature.MaxAllowedEventsCountInOneYear >= totalEventCountByOrganization; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual async Task<bool> CanAddNewTrack(Event @event) |
|
|
public virtual async Task<bool> CanAddNewTrackAsync(Event @event) |
|
|
{ |
|
|
{ |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
|
|
|
|
|
|
|
|
var tracksCount = @event.Tracks.Count; |
|
|
var tracksCount = @event.Tracks.Count; |
|
|
tracksCount++; |
|
|
return currentPlanOfOrganization.Feature.MaxAllowedTracksCountInOneEvent > tracksCount; |
|
|
return currentPlanOfOrganization.Feature.MaxAllowedTracksCountInOneEvent >= tracksCount; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual async Task<bool> CanRegisterToEvent(Event @event) |
|
|
public virtual async Task<bool> CanRegisterToEventAsync(Event @event) |
|
|
{ |
|
|
{ |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
|
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
|
|
|
|
|
|
|
|
var attendeesCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id); |
|
|
var attendeesCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id); |
|
|
attendeesCount++; |
|
|
return currentPlanOfOrganization.Feature.MaxAllowedAttendeesCountInOneEvent > attendeesCount; |
|
|
return currentPlanOfOrganization.Feature.MaxAllowedAttendeesCountInOneEvent >= attendeesCount; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async Task<PlanInfoDefinition> GetCurrentPlanByOrganizationIdAsync(Guid organizationId) |
|
|
private async Task<PlanInfoDefinition> GetCurrentPlanByOrganizationIdAsync(Guid organizationId) |
|
|
{ |
|
|
{ |
|
|
var organization = await _organizationRepository.GetAsync(organizationId); |
|
|
var organization = await _organizationRepository.GetAsync(organizationId); |
|
|
return await _planInfoDefinitionStore.GetPlanInfoByTypeAsync(organization.PlanType); |
|
|
return _planInfoOptions.Value.GetPlanInfoByType(organization.PlanType); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|