예제 #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> SaveReunion([FromBody] Reunion reunion)
        {
            _logger.LogInformation($"ReunionsController.SaveReunion|{JsonConvert.SerializeObject(reunion)}");
            try
            {
                if (!reunion.Id.HasValue)
                {
                    throw new Exception("Reunion doesn't have a valid ID");
                }

                if (string.IsNullOrWhiteSpace(reunion.ActionUserId))
                {
                    reunion.ActionUserId = Helpers.GetUserId(HttpContext.User);
                }

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

                return(new OkObjectResult(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);
                if (!reunion.IsValid())
                {
                    return(BadRequest(reunion));
                }

                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #3
0
        public void InvalidReunionFails(string name, string startDate, string endDate)
        {
            Reunion reunion = new Reunion
            {
                Name      = name,
                StartDate = string.IsNullOrEmpty(startDate) ? (DateTime?)null : DateTime.Parse(startDate),
                EndDate   = string.IsNullOrEmpty(endDate) ? (DateTime?)null : DateTime.Parse(endDate)
            };

            Assert.False(reunion.IsValid());
        }