Пример #1
0
        public async Task UpdateEventAsync(EditEventDto eventDto)
        {
            var eventToUpdate = await _eventsDbSet
                                .Include(e => e.EventOptions)
                                .Include(e => e.EventParticipants)
                                .FirstOrDefaultAsync(e => e.Id == eventDto.Id && e.OrganizationId == eventDto.OrganizationId);

            var totalOptionsProvided = eventDto.NewOptions.Count() + eventDto.EditedOptions.Count();

            eventDto.MaxOptions = FindOutMaxChoices(totalOptionsProvided, eventDto.MaxOptions);
            eventDto.RegistrationDeadlineDate = SetRegistrationDeadline(eventDto);

            var hasPermission = await _permissionService.UserHasPermissionAsync(eventDto, AdministrationPermissions.Event);

            _eventValidationService.CheckIfEventExists(eventToUpdate);

            if (eventToUpdate == null)
            {
                return;
            }

            _eventValidationService.CheckIfUserHasPermission(eventDto.UserId, eventToUpdate.ResponsibleUserId, hasPermission);
            _eventValidationService.CheckIfUserHasPermissionToPin(eventDto.IsPinned, eventToUpdate.IsPinned, hasPermission);
            _eventValidationService.CheckIfCreatingEventHasInsufficientOptions(eventDto.MaxOptions, totalOptionsProvided);
            _eventValidationService.CheckIfCreatingEventHasNoChoices(eventDto.MaxOptions, totalOptionsProvided);
            _eventValidationService.CheckIfAttendOptionsAllowedToUpdate(eventDto, eventToUpdate);
            await ValidateEvent(eventDto);

            if (eventDto.ResetParticipantList)
            {
                await _eventParticipationService.ResetAttendeesAsync(eventDto.Id, eventDto);
            }

            await UpdateWallAsync(eventToUpdate, eventDto);

            UpdateEventInfo(eventDto, eventToUpdate);
            UpdateEventOptions(eventDto, eventToUpdate);

            await _uow.SaveChangesAsync(false);

            eventToUpdate.Description = _markdownConverter.ConvertToHtml(eventToUpdate.Description);
        }