mirror of https://github.com/abpframework/eventhub
41 changed files with 3180 additions and 160 deletions
@ -1,9 +1,11 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace EventHub.Organizations.PaymentRequests; |
namespace EventHub.Organizations.Plans; |
||||
|
|
||||
public interface IPlanInfoDefinitionStore |
public interface IPlanInfoDefinitionStore |
||||
{ |
{ |
||||
Task<List<PlanInfoDefinition>> GetPlanInfosAsync(); |
Task<List<PlanInfoDefinition>> GetPlanInfosAsync(); |
||||
|
|
||||
|
Task<PlanInfoDefinition> GetPlanInfoByTypeAsync(OrganizationPlanType type); |
||||
} |
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Events; |
||||
|
using EventHub.Events.Registrations; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace EventHub.Organizations.Plans; |
||||
|
|
||||
|
public class PlanFeatureManager : ITransientDependency |
||||
|
{ |
||||
|
private readonly IPlanInfoDefinitionStore _planInfoDefinitionStore; |
||||
|
private readonly IRepository<Organization, Guid> _organizationRepository; |
||||
|
private readonly IRepository<Event, Guid> _eventRepository; |
||||
|
private readonly IEventRegistrationRepository _eventRegistrationRepository; |
||||
|
|
||||
|
public PlanFeatureManager( |
||||
|
IPlanInfoDefinitionStore planInfoDefinitionStore, |
||||
|
IRepository<Organization, Guid> organizationRepository, |
||||
|
IRepository<Event, Guid> eventRepository, |
||||
|
IEventRegistrationRepository eventRegistrationRepository) |
||||
|
{ |
||||
|
_planInfoDefinitionStore = planInfoDefinitionStore; |
||||
|
_organizationRepository = organizationRepository; |
||||
|
_eventRepository = eventRepository; |
||||
|
_eventRegistrationRepository = eventRegistrationRepository; |
||||
|
} |
||||
|
|
||||
|
public async Task<bool> CanCreateNewEvent(Guid organizationId) |
||||
|
{ |
||||
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(organizationId); |
||||
|
|
||||
|
var totalEventCountByOrganization = await _eventRepository.CountAsync(x => x.OrganizationId == organizationId); |
||||
|
totalEventCountByOrganization++; |
||||
|
return currentPlanOfOrganization.Feature.MaxAllowedEventsCount >= totalEventCountByOrganization; |
||||
|
} |
||||
|
|
||||
|
public async Task<bool> CanAddNewTrack(Event @event) |
||||
|
{ |
||||
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
||||
|
|
||||
|
var tracksCount = @event.Tracks.Count; |
||||
|
tracksCount++; |
||||
|
return currentPlanOfOrganization.Feature.MaxAllowedTracksCountInOneEvent >= tracksCount; |
||||
|
} |
||||
|
|
||||
|
public async Task<bool> CanRegisterToEvent(Event @event) |
||||
|
{ |
||||
|
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId); |
||||
|
|
||||
|
var attendeesCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id); |
||||
|
attendeesCount++; |
||||
|
return currentPlanOfOrganization.Feature.MaxAllowedAttendeesCountInOneEvent >= attendeesCount; |
||||
|
} |
||||
|
|
||||
|
private async Task<PlanInfoDefinition> GetCurrentPlanByOrganizationIdAsync(Guid organizationId) |
||||
|
{ |
||||
|
var organization = await _organizationRepository.GetAsync(organizationId); |
||||
|
return await _planInfoDefinitionStore.GetPlanInfoByTypeAsync(organization.PlanType); |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,6 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
|
|
||||
namespace EventHub.Organizations.PaymentRequests; |
namespace EventHub.Organizations.Plans; |
||||
|
|
||||
public class PlanInfoOptions |
public class PlanInfoOptions |
||||
{ |
{ |
||||
File diff suppressed because it is too large
@ -0,0 +1,57 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace EventHub.Migrations |
||||
|
{ |
||||
|
public partial class Updated_Organization : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "IsPremium", |
||||
|
table: "EhOrganizations"); |
||||
|
|
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "PremiumEndDate", |
||||
|
table: "EhOrganizations", |
||||
|
newName: "PaidEnrollmentEndDate"); |
||||
|
|
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "IsSendPremiumReminderEmail", |
||||
|
table: "EhOrganizations", |
||||
|
newName: "IsSendPaidEnrollmentReminderEmail"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<byte>( |
||||
|
name: "PlanType", |
||||
|
table: "EhOrganizations", |
||||
|
type: "smallint", |
||||
|
nullable: false, |
||||
|
defaultValue: (byte)0); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "PlanType", |
||||
|
table: "EhOrganizations"); |
||||
|
|
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "PaidEnrollmentEndDate", |
||||
|
table: "EhOrganizations", |
||||
|
newName: "PremiumEndDate"); |
||||
|
|
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "IsSendPaidEnrollmentReminderEmail", |
||||
|
table: "EhOrganizations", |
||||
|
newName: "IsSendPremiumReminderEmail"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<bool>( |
||||
|
name: "IsPremium", |
||||
|
table: "EhOrganizations", |
||||
|
type: "boolean", |
||||
|
nullable: false, |
||||
|
defaultValue: false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue