mirror of https://github.com/abpframework/eventhub
19 changed files with 396 additions and 127 deletions
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventWithDetails |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string OrganizationDisplayName { get; set; } |
|||
|
|||
public int AttendeeCount { get; set; } |
|||
|
|||
public DateTime StartTime { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public interface IEventRepository : IRepository<Event, Guid> |
|||
{ |
|||
Task<int> GetCountAsync( |
|||
string title = null, |
|||
string organizationDisplayName = null, |
|||
int? minAttendeeCount = null, |
|||
int? maxAttendeeCount = null, |
|||
DateTime? minStartTime = null, |
|||
DateTime? maxStartTime = null, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
Task<List<EventWithDetails>> GetListAsync( |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
string title = null, |
|||
string organizationDisplayName = null, |
|||
int? minAttendeeCount = null, |
|||
int? maxAttendeeCount = null, |
|||
DateTime? minStartTime = null, |
|||
DateTime? maxStartTime = null, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using Volo.Abp.Auditing; |
|||
|
|||
namespace EventHub.Events.Registrations |
|||
{ |
|||
public class EventRegistrationWithDetails : IHasCreationTime |
|||
{ |
|||
public Guid UserId { get; set; } |
|||
|
|||
public string UserName { get; set; } |
|||
|
|||
public string Email { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public string Surname { get; set; } |
|||
|
|||
public DateTime CreationTime { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EventHub.Events.Registrations |
|||
{ |
|||
public interface IEventRegistrationRepository : IRepository<EventRegistration, Guid> |
|||
{ |
|||
Task<int> GetCountAsync(Guid eventId, CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<EventRegistrationWithDetails>> GetListAsync( |
|||
Guid eventId, |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Identity; |
|||
|
|||
namespace EventHub.Users |
|||
{ |
|||
public interface IUserRepository : IRepository<IdentityUser, Guid> |
|||
{ |
|||
Task<List<IdentityUser>> GetListAsync( |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
string username = null, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
Task<int> GetCountAsync( |
|||
string username = null, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Events; |
|||
using EventHub.Events.Registrations; |
|||
using EventHub.Organizations; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace EventHub.EntityFrameworkCore.Events |
|||
{ |
|||
public class EventRepository : EfCoreRepository<EventHubDbContext, Event, Guid>, IEventRepository |
|||
{ |
|||
public EventRepository(IDbContextProvider<EventHubDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<int> GetCountAsync( |
|||
string title = null, |
|||
string organizationDisplayName = null, |
|||
int? minAttendeeCount = null, |
|||
int? maxAttendeeCount = null, |
|||
DateTime? minStartTime = null, |
|||
DateTime? maxStartTime = null, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
|
|||
var eventQueryable = await GetQueryableAsync(); |
|||
var eventRegistrationQueryable = dbContext.Set<EventRegistration>().AsQueryable(); |
|||
var organizationQueryable = dbContext.Set<Organization>().AsQueryable(); |
|||
|
|||
var query = (from @event in eventQueryable |
|||
join organization in organizationQueryable on @event.OrganizationId equals organization.Id |
|||
select new |
|||
{ |
|||
Event = @event, |
|||
Organization = organization, |
|||
AttendeeCount = (from eventRegistration in eventRegistrationQueryable |
|||
where eventRegistration.EventId == @event.Id |
|||
select @eventRegistration).Count() |
|||
}) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(title), x => x.Event.Title.ToLower().Contains(title.ToLower())) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(organizationDisplayName), x => x.Organization.DisplayName.ToLower().Contains(organizationDisplayName.ToLower())) |
|||
.WhereIf(minStartTime.HasValue, x => x.Event.StartTime >= minStartTime) |
|||
.WhereIf(maxStartTime.HasValue, x => x.Event.StartTime <= maxStartTime) |
|||
.WhereIf(minAttendeeCount.HasValue, x => x.AttendeeCount >= minAttendeeCount) |
|||
.WhereIf(maxAttendeeCount.HasValue, x => x.AttendeeCount <= maxAttendeeCount); |
|||
|
|||
return await query.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<EventWithDetails>> GetListAsync( |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
string title = null, |
|||
string organizationDisplayName = null, |
|||
int? minAttendeeCount = null, |
|||
int? maxAttendeeCount = null, |
|||
DateTime? minStartTime = null, |
|||
DateTime? maxStartTime = null, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
|
|||
var eventQueryable = await GetQueryableAsync(); |
|||
var eventRegistrationQueryable = dbContext.Set<EventRegistration>().AsQueryable(); |
|||
var organizationQueryable = dbContext.Set<Organization>().AsQueryable(); |
|||
|
|||
var query = (from @event in eventQueryable |
|||
join organization in organizationQueryable on @event.OrganizationId equals organization.Id |
|||
select new EventWithDetails |
|||
{ |
|||
Id = @event.Id, |
|||
Title = @event.Title, |
|||
StartTime = @event.StartTime, |
|||
OrganizationDisplayName = organization.DisplayName, |
|||
AttendeeCount = (from eventRegistration in eventRegistrationQueryable |
|||
where eventRegistration.EventId == @event.Id |
|||
select @eventRegistration).Count() |
|||
}) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(title), x => x.Title.ToLower().Contains(title.ToLower())) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(organizationDisplayName), |
|||
x => x.OrganizationDisplayName.ToLower().Contains(organizationDisplayName.ToLower())) |
|||
.WhereIf(minStartTime.HasValue, x => x.StartTime >= minStartTime) |
|||
.WhereIf(maxStartTime.HasValue, x => x.StartTime <= maxStartTime) |
|||
.WhereIf(minAttendeeCount.HasValue, x => x.AttendeeCount >= minAttendeeCount) |
|||
.WhereIf(maxAttendeeCount.HasValue, x => x.AttendeeCount <= maxAttendeeCount) |
|||
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? EventConsts.DefaultSorting : sorting) |
|||
.PageBy(skipCount, maxResultCount); |
|||
|
|||
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using EventHub.Events.Registrations; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Identity; |
|||
|
|||
namespace EventHub.EntityFrameworkCore.Events.Registrations |
|||
{ |
|||
public class EventRegistrationRepository : EfCoreRepository<EventHubDbContext, EventRegistration, Guid>, IEventRegistrationRepository |
|||
{ |
|||
public EventRegistrationRepository(IDbContextProvider<EventHubDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<int> GetCountAsync(Guid eventId, CancellationToken cancellationToken = default) |
|||
{ |
|||
var userQueryable = (await GetDbContextAsync()).Set<IdentityUser>().AsQueryable(); |
|||
|
|||
var query = from eventRegistration in (await GetQueryableAsync()) |
|||
join user in userQueryable on eventRegistration.UserId equals user.Id |
|||
where eventRegistration.EventId == eventId |
|||
select user; |
|||
|
|||
return await query.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<EventRegistrationWithDetails>> GetListAsync( |
|||
Guid eventId, |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var userQueryable = (await GetDbContextAsync()).Set<IdentityUser>().AsQueryable(); |
|||
|
|||
var query = (from eventRegistration in (await GetQueryableAsync()) |
|||
join user in userQueryable on eventRegistration.UserId equals user.Id |
|||
where eventRegistration.EventId == eventId |
|||
select new EventRegistrationWithDetails |
|||
{ |
|||
UserId = user.Id, |
|||
Name = user.Name, |
|||
Surname = user.Surname, |
|||
UserName = user.UserName, |
|||
Email = user.Email, |
|||
CreationTime = user.CreationTime |
|||
}) |
|||
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? nameof(EventRegistrationWithDetails.CreationTime) : sorting) |
|||
.PageBy(skipCount, maxResultCount); |
|||
|
|||
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Users; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Identity; |
|||
|
|||
namespace EventHub.EntityFrameworkCore.Users |
|||
{ |
|||
public class UserRepository : EfCoreRepository<EventHubDbContext, IdentityUser, Guid>, IUserRepository |
|||
{ |
|||
public UserRepository(IDbContextProvider<EventHubDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<int> GetCountAsync(string username = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(username), user => user.UserName.ToLower().Contains(username.ToLower())) |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<IdentityUser>> GetListAsync( |
|||
string sorting = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = int.MaxValue, |
|||
string username = null, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.WhereIf(!string.IsNullOrWhiteSpace(username), user => user.UserName.ToLower().Contains(username.ToLower())) |
|||
.OrderBy(string.IsNullOrWhiteSpace(sorting) ? nameof(IdentityUser.CreationTime) : sorting) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue