예제 #1
0
        public async Task <IActionResult> NewReunion([FromBody] NewReunionRequest request)
        {
            _logger.LogInformation($"{GetType()}.NewReunion|{JsonConvert.SerializeObject(request)}");
            Reunion reunion = null;

            try
            {
                reunion = NewReunionRequestMapper.Map(request);

                if (!reunion.IsValid())
                {
                    return(BadRequest(request));
                }

                var result = await _reunionService.SaveReunionAsync(reunion)
                             .ConfigureAwait(continueOnCapturedContext: false);

                await _reunionService.AddReunionOrganizer(OrganizerRequest.AddOrganizerRequest(result.Id.Value, reunion.ActionUserId, reunion.ActionUserId))
                .ConfigureAwait(continueOnCapturedContext: false);

                var resp = CreatedAtAction("GetReunion",
                                           routeValues: new { id = result.Id.Value },
                                           value: result);
                resp.ContentTypes.Add(ContentType.Json);
                return(resp);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);

                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #2
0
        public async Task <IActionResult> OrganizerOperations([FromBody] OrganizerRequest request)
        {
            _logger.LogInformation($"ReunionsController.GetOrganizers|{request}");
            try
            {
                switch (request.Action)
                {
                case Constants.OrganizerAction.List:
                    var results = await _reunionService.GetReunionOrganizers(request)
                                  .ConfigureAwait(continueOnCapturedContext: false);

                    return(Ok(results));

                case Constants.OrganizerAction.Add:
                    await _reunionService.AddReunionOrganizer(request)
                    .ConfigureAwait(continueOnCapturedContext: false);

                    return(Ok());

                case Constants.OrganizerAction.Remove:
                    await _reunionService.RemoveReunionOrganizer(request)
                    .ConfigureAwait(continueOnCapturedContext: false);

                    return(Ok());

                default:
                    throw new ArgumentException("Invalid action specified");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #3
0
        public async Task <IEnumerable <User> > GetReunionOrganizers(OrganizerRequest request)
        {
            if (request.Action != Constants.OrganizerAction.List)
            {
                throw new Exception($"Invalid action specified for GetReunionOrganizers|{request.Action}");
            }

            if (!await _userRepository.ValidateUserIdAsync(request.ActionUserId))
            {
                throw new Exception($"Invalid user id when saving reunion: '{request.ReunionId}'");
            }

            if (!await CheckUserWriteAccess(request.ActionUserId, request.ReunionId))
            {
                throw new UnauthorizedAccessException($"User {request.ActionUserId} does not have access to write for reunion {request.ReunionId}");
            }

            return(await _userRepository.GetReunionOrganizers(request.ReunionId)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
예제 #4
0
        public async Task RemoveReunionOrganizer(OrganizerRequest request)
        {
            if (request.Action != Constants.OrganizerAction.Remove)
            {
                throw new Exception($"Invalid action specified for RemoveReunionOrganizer|{request.Action}");
            }

            if (!await _userRepository.ValidateEmailAsync(request.Email) || !await _userRepository.ValidateUserIdAsync(request.ActionUserId))
            {
                throw new Exception($"Invalid user id when saving reunion: '{request.ReunionId}'");
            }

            if (!await CheckUserWriteAccess(request.ActionUserId, request.ReunionId))
            {
                throw new UnauthorizedAccessException($"User {request.ActionUserId} does not have access to write for reunion {request.ReunionId}");
            }

            await _reunionRepository.RemoveReunionOrganizer(request.ReunionId, request.Email)
            .ConfigureAwait(continueOnCapturedContext: false);
        }
예제 #5
0
        public async Task AddReunionOrganizer(OrganizerRequest request)
        {
            if (request.Action != Constants.OrganizerAction.Add)
            {
                throw new Exception($"Invalid action specified for AddReunionOrganizer|{request.Action}");
            }

            IEnumerable <User> organizers = await _userRepository.GetReunionOrganizers(request.ReunionId)
                                            .ConfigureAwait(continueOnCapturedContext: false);

            // Special validation for first reunion organizer at reunion creation
            if (organizers.Count() == 0 && request.Email == request.ActionUserId)
            {
                if (!await _userRepository.ValidateUserIdAsync(request.ActionUserId))
                {
                    throw new Exception($"Invalid user id when saving reunion: '{request.ReunionId}'");
                }

                User user = await _userRepository.GetUserByIdAsync(request.ActionUserId)
                            .ConfigureAwait(continueOnCapturedContext: false);

                await _reunionRepository.AddReunionOrganizer(request.ReunionId, user.Email)
                .ConfigureAwait(continueOnCapturedContext: false);
            }
            else
            {
                if (!await _userRepository.ValidateEmailAsync(request.Email) || !await _userRepository.ValidateUserIdAsync(request.ActionUserId))
                {
                    throw new Exception($"Invalid user id when saving reunion: '{request.ReunionId}'");
                }

                if (!await CheckUserWriteAccess(request.ActionUserId, request.ReunionId))
                {
                    throw new UnauthorizedAccessException($"User {request.ActionUserId} does not have access to write for reunion {request.ReunionId}");
                }

                await _reunionRepository.AddReunionOrganizer(request.ReunionId, request.Email)
                .ConfigureAwait(continueOnCapturedContext: false);
            }
        }