Browse Source

Admin: Add or Remove attends according to UserPick component

pull/53/head
Engincan VESKE 5 years ago
parent
commit
f528d74675
  1. 3
      src/EventHub.Admin.Application.Contracts/Events/EventListFilterDto.cs
  2. 2
      src/EventHub.Admin.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs
  3. 9
      src/EventHub.Admin.Application/Events/EventAppService.cs
  4. 34
      src/EventHub.Admin.Application/Events/Registrations/EventRegistrationAppService.cs
  5. 4
      src/EventHub.Admin.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs
  6. 9
      src/EventHub.Admin.Web/Pages/AttendeeDetail.razor.cs
  7. 10
      src/EventHub.Admin.Web/Pages/EventManagement.razor
  8. 10
      src/EventHub.Admin.Web/Pages/EventManagement.razor.cs
  9. 5
      src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs

3
src/EventHub.Admin.Application.Contracts/Events/EventListFilterDto.cs

@ -5,7 +5,8 @@ namespace EventHub.Admin.Events
{ {
public class EventListFilterDto : PagedAndSortedResultRequestDto public class EventListFilterDto : PagedAndSortedResultRequestDto
{ {
public DateTime? StartTime { get; set; } public DateTime? MinStartTime { get; set; }
public DateTime? MaxStartTime { get; set; }
public string Title { get; set; } public string Title { get; set; }

2
src/EventHub.Admin.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs

@ -10,7 +10,7 @@ namespace EventHub.Admin.Events.Registrations
{ {
Task<PagedResultDto<EventAttendeeDto>> GetAttendeesAsync(GetEventRegistrationListInput input); Task<PagedResultDto<EventAttendeeDto>> GetAttendeesAsync(GetEventRegistrationListInput input);
Task RemoveAttendeeAsync(Guid eventId, Guid attendeeId); Task UnRegisterAttendeeAsync(Guid eventId, Guid attendeeId);
Task RegisterUsersAsync(Guid eventId, List<Guid> userIds); Task RegisterUsersAsync(Guid eventId, List<Guid> userIds);

9
src/EventHub.Admin.Application/Events/EventAppService.cs

@ -3,17 +3,19 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventHub.Admin.Permissions;
using EventHub.Countries; using EventHub.Countries;
using EventHub.Events; using EventHub.Events;
using EventHub.Events.Registrations; using EventHub.Events.Registrations;
using EventHub.Organizations; using EventHub.Organizations;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace EventHub.Admin.Events namespace EventHub.Admin.Events
{ {
//[Authorize(EventHubPermissions.Events.Default)] [Authorize(EventHubPermissions.Events.Default)]
public class EventAppService : EventHubAdminAppService, IEventAppService public class EventAppService : EventHubAdminAppService, IEventAppService
{ {
private readonly IRepository<Event, Guid> _eventRepository; private readonly IRepository<Event, Guid> _eventRepository;
@ -70,7 +72,8 @@ namespace EventHub.Admin.Events
}) })
.WhereIf(!string.IsNullOrWhiteSpace(input.Title), x => x.Title.ToLower().Contains(input.Title.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(input.Title), x => x.Title.ToLower().Contains(input.Title.ToLower()))
.WhereIf(!string.IsNullOrWhiteSpace(input.OrganizationDisplayName), x => x.OrganizationDisplayName.ToLower().Contains(input.OrganizationDisplayName.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(input.OrganizationDisplayName), x => x.OrganizationDisplayName.ToLower().Contains(input.OrganizationDisplayName.ToLower()))
.WhereIf(input.StartTime.HasValue, x => x.StartTime > input.StartTime) .WhereIf(input.MinStartTime.HasValue, x => x.StartTime >= input.MinStartTime)
.WhereIf(input.MaxStartTime.HasValue, x => x.StartTime <= input.MaxStartTime)
.WhereIf(input.MinAttendeeCount.HasValue, x => x.AttendeeCount >= input.MinAttendeeCount) .WhereIf(input.MinAttendeeCount.HasValue, x => x.AttendeeCount >= input.MinAttendeeCount)
.WhereIf(input.MaxAttendeeCount.HasValue, x => x.AttendeeCount <= input.MaxAttendeeCount); .WhereIf(input.MaxAttendeeCount.HasValue, x => x.AttendeeCount <= input.MaxAttendeeCount);
@ -83,7 +86,7 @@ namespace EventHub.Admin.Events
return new PagedResultDto<EventInListDto>(totalCount, events); return new PagedResultDto<EventInListDto>(totalCount, events);
} }
//[Authorize(EventHubPermissions.Events.Update)] [Authorize(EventHubPermissions.Events.Update)]
public async Task UpdateAsync(Guid id, UpdateEventDto input) public async Task UpdateAsync(Guid id, UpdateEventDto input)
{ {
var @event = await _eventRepository.GetAsync(id); var @event = await _eventRepository.GetAsync(id);

34
src/EventHub.Admin.Application/Events/Registrations/EventRegistrationAppService.cs

@ -10,10 +10,11 @@ using Volo.Abp.Identity;
using EventHub.Events.Registrations; using EventHub.Events.Registrations;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using EventHub.Events; using EventHub.Events;
using Volo.Abp;
namespace EventHub.Admin.Events.Registrations namespace EventHub.Admin.Events.Registrations
{ {
//[Authorize(EventHubPermissions.Events.Registrations.Default)] [Authorize(EventHubPermissions.Events.Registrations.Default)]
public class EventRegistrationAppService : EventHubAdminAppService, IEventRegistrationAppService public class EventRegistrationAppService : EventHubAdminAppService, IEventRegistrationAppService
{ {
private readonly IRepository<IdentityUser, Guid> _userRepository; private readonly IRepository<IdentityUser, Guid> _userRepository;
@ -21,7 +22,6 @@ namespace EventHub.Admin.Events.Registrations
private readonly IRepository<Event, Guid> _eventRepository; private readonly IRepository<Event, Guid> _eventRepository;
private readonly EventRegistrationManager _eventRegistrationManager; private readonly EventRegistrationManager _eventRegistrationManager;
public EventRegistrationAppService( public EventRegistrationAppService(
IRepository<IdentityUser, Guid> userRepository, IRepository<IdentityUser, Guid> userRepository,
IRepository<EventRegistration, Guid> eventRegistrationRepository, IRepository<EventRegistration, Guid> eventRegistrationRepository,
@ -61,16 +61,13 @@ namespace EventHub.Admin.Events.Registrations
); );
} }
//[Authorize(EventHubPermissions.Events.Registrations.RemoveAttendee)] [Authorize(EventHubPermissions.Events.Registrations.RemoveAttendee)]
public async Task RemoveAttendeeAsync(Guid eventId, Guid attendeeId) public async Task UnRegisterAttendeeAsync(Guid eventId, Guid attendeeId)
{ {
await _eventRegistrationManager.UnregisterAsync( await _eventRegistrationRepository.DeleteAsync(x => x.EventId == eventId && x.UserId == attendeeId);
await _eventRepository.GetAsync(eventId),
await _userRepository.GetAsync(attendeeId)
);
} }
//[Authorize(EventHubPermissions.Events.Registrations.AddAttendee)] [Authorize(EventHubPermissions.Events.Registrations.AddAttendee)]
public async Task RegisterUsersAsync(Guid eventId, List<Guid> userIds) public async Task RegisterUsersAsync(Guid eventId, List<Guid> userIds)
{ {
if (userIds == null || !userIds.Any()) if (userIds == null || !userIds.Any())
@ -83,11 +80,15 @@ namespace EventHub.Admin.Events.Registrations
var userQueryable = await _userRepository.GetQueryableAsync(); var userQueryable = await _userRepository.GetQueryableAsync();
var query = userQueryable.Where(user => userIds.Contains(user.Id)); var query = userQueryable.Where(user => userIds.Contains(user.Id));
await CheckEventCapacityAsync(@event);
var users = await AsyncExecuter.ToListAsync(query); var users = await AsyncExecuter.ToListAsync(query);
foreach (var user in users) foreach (var user in users)
{ {
await _eventRegistrationManager.RegisterAsync(@event, user); if (!await _eventRegistrationManager.IsRegisteredAsync(@event, user))
{
await _eventRegistrationRepository.InsertAsync(await _eventRegistrationManager.CreateAsync(@event.Id, user.Id));
}
} }
} }
@ -104,5 +105,16 @@ namespace EventHub.Admin.Events.Registrations
return await AsyncExecuter.ToListAsync(query); return await AsyncExecuter.ToListAsync(query);
} }
private async Task CheckEventCapacityAsync(Event @event)
{
var registrationCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id);
if (@event.Capacity != null && registrationCount >= @event.Capacity)
{
throw new BusinessException(EventHubErrorCodes.CapacityOfEventFull)
.WithData("EventTitle", @event.Title);
}
}
} }
} }

4
src/EventHub.Admin.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs

@ -43,9 +43,9 @@ namespace EventHub.Admin.Controllers.Events.Registrations
} }
[HttpDelete] [HttpDelete]
public Task RemoveAttendeeAsync(Guid eventId, Guid attendeeId) public Task UnRegisterAttendeeAsync(Guid eventId, Guid attendeeId)
{ {
return _eventRegistrationAppService.RemoveAttendeeAsync(eventId, attendeeId); return _eventRegistrationAppService.UnRegisterAttendeeAsync(eventId, attendeeId);
} }
} }
} }

9
src/EventHub.Admin.Web/Pages/AttendeeDetail.razor.cs

@ -73,7 +73,7 @@ namespace EventHub.Admin.Web.Pages
} }
private async Task RemoveAttendeeAsync(EventAttendeeDto attendee) private async Task RemoveAttendeeAsync(EventAttendeeDto attendee)
{ {
await EventRegistrationAppService.RemoveAttendeeAsync(EventId, attendee.Id); await EventRegistrationAppService.UnRegisterAttendeeAsync(EventId, attendee.Id);
await GetAttendeesAsync(); await GetAttendeesAsync();
} }
@ -87,8 +87,13 @@ namespace EventHub.Admin.Web.Pages
.Select(x => x.Key) .Select(x => x.Key)
.ToList(); .ToList();
await EventRegistrationAppService.RegisterUsersAsync(EventId, selectedUserIds); var removedAttendees = SelectedUserIds.Except(selectedUserIds).ToList();
foreach (var attendeeId in removedAttendees)
{
await EventRegistrationAppService.UnRegisterAttendeeAsync(EventId, attendeeId);
}
await EventRegistrationAppService.RegisterUsersAsync(EventId, selectedUserIds);
await UserPickerModalRef.CloseUserPickerModalAsync(); await UserPickerModalRef.CloseUserPickerModalAsync();
await GetAttendeesAsync(); await GetAttendeesAsync();

10
src/EventHub.Admin.Web/Pages/EventManagement.razor

@ -32,8 +32,14 @@
</Column> </Column>
<Column ColumnSize="ColumnSize.Is3"> <Column ColumnSize="ColumnSize.Is3">
<Field> <Field>
<FieldLabel>@L["StartTime"]</FieldLabel> <FieldLabel>@L["MinStartTime"]</FieldLabel>
<DateEdit TValue="DateTime?" Date="@Filter.StartTime" DateChanged="OnSelectedDateChanged"/> <DateEdit TValue="DateTime?" Date="@Filter.MinStartTime" DateChanged="OnSelectedDateChangedForMinStartTime" />
</Field>
</Column>
<Column ColumnSize="ColumnSize.Is3">
<Field>
<FieldLabel>@L["MaxEndTime"]</FieldLabel>
<DateEdit TValue="DateTime?" Date="@Filter.MaxStartTime" DateChanged="OnSelectedDateChangedForMaxStartTime" />
</Field> </Field>
</Column> </Column>
<Column ColumnSize="ColumnSize.Is3"> <Column ColumnSize="ColumnSize.Is3">

10
src/EventHub.Admin.Web/Pages/EventManagement.razor.cs

@ -125,9 +125,15 @@ namespace EventHub.Admin.Web.Pages
} }
} }
private async Task OnSelectedDateChanged(DateTime? changedDate) private async Task OnSelectedDateChangedForMinStartTime(DateTime? minStartTime)
{ {
Filter.StartTime = changedDate; Filter.MinStartTime = minStartTime;
await GetEventsAsync();
}
private async Task OnSelectedDateChangedForMaxStartTime(DateTime? maxStartTime)
{
Filter.MaxStartTime = maxStartTime;
await GetEventsAsync(); await GetEventsAsync();
} }

5
src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs

@ -16,6 +16,11 @@ namespace EventHub.Events.Registrations
_eventRegistrationRepository = eventRegistrationRepository; _eventRegistrationRepository = eventRegistrationRepository;
} }
public async Task<EventRegistration> CreateAsync(Guid eventId, Guid userId)
{
return new EventRegistration(GuidGenerator.Create(), eventId, userId);
}
public async Task RegisterAsync( public async Task RegisterAsync(
Event @event, Event @event,
IdentityUser user) IdentityUser user)

Loading…
Cancel
Save