Пример #1
0
        public async Task DeleteAsync(Guid id, UserAndOrganizationDto userOrg)
        {
            var @event = await _eventsDbSet
                         .Include(e => e.EventOptions)
                         .Include(e => e.EventParticipants)
                         .SingleOrDefaultAsync(e => e.Id == id && e.OrganizationId == userOrg.OrganizationId);

            _eventValidationService.CheckIfEventExists(@event);
            var isAdmin = await _permissionService.UserHasPermissionAsync(userOrg, AdministrationPermissions.Event);

            // ReSharper disable once PossibleNullReferenceException
            _eventValidationService.CheckIfUserHasPermission(userOrg.UserId, @event.ResponsibleUserId, isAdmin);
            _eventValidationService.CheckIfEventEndDateIsExpired(@event.EndDate);

            var timestamp = DateTime.UtcNow;

            @event.Modified   = timestamp;
            @event.ModifiedBy = userOrg.UserId;

            await _eventParticipationService.DeleteByEventAsync(id, userOrg.UserId);

            await _eventUtilitiesService.DeleteByEventAsync(id, userOrg.UserId);

            _eventsDbSet.Remove(@event);

            await _uow.SaveChangesAsync(false);

            await _wallService.DeleteWallAsync(@event.WallId, userOrg, WallType.Events);
        }
Пример #2
0
        public async Task ResetAttendeesAsync(Guid eventId, UserAndOrganizationDto userOrg)
        {
            var @event = await _eventsDbSet
                         .Include(e => e.EventParticipants)
                         .Include(e => e.EventOptions)
                         .Include(e => e.EventType)
                         .Include(e => e.EventParticipants.Select(participant => participant.ApplicationUser))
                         .Include(e => e.EventParticipants.Select(participant => participant.ApplicationUser.Manager))
                         .SingleOrDefaultAsync(e => e.Id == eventId && e.OrganizationId == userOrg.OrganizationId);

            _eventValidationService.CheckIfEventExists(@event);
            var hasPermission = await _permissionService.UserHasPermissionAsync(userOrg, AdministrationPermissions.Event);

            // ReSharper disable once PossibleNullReferenceException
            _eventValidationService.CheckIfUserHasPermission(userOrg.UserId, @event.ResponsibleUserId, hasPermission);
            _eventValidationService.CheckIfEventEndDateIsExpired(@event.EndDate);

            var users     = @event.EventParticipants.Select(p => p.ApplicationUserId).ToList();
            var timestamp = DateTime.UtcNow;

            foreach (var participant in @event.EventParticipants)
            {
                participant.UpdateMetadata(userOrg.UserId, timestamp);
            }

            await _uow.SaveChangesAsync(false);

            if ([email protected])
            {
                await RemoveParticipantsAsync(@event, userOrg);

                _asyncRunner.Run <IEventNotificationService>(async notifier => await notifier.NotifyRemovedEventParticipantsAsync(@event.Name, @event.Id, userOrg.OrganizationId, users),
                                                             _uow.ConnectionName);

                return;
            }

            var userEventAttendStatusDto = MapEventToUserEventAttendStatusChangeEmailDto(@event).ToList();

            await RemoveParticipantsAsync(@event, userOrg);

            _asyncRunner.Run <IEventNotificationService>(async notifier => await notifier.NotifyRemovedEventParticipantsAsync(@event.Name, @event.Id, userOrg.OrganizationId, users),
                                                         _uow.ConnectionName);

            NotifyManagers(userEventAttendStatusDto);
        }