Ejemplo n.º 1
0
        private VisitInfoDto CreateInfoDto(VisitInfo info)
        {
            var infoDto = new VisitInfoDto
            {
                Id                     = info.Id,
                Description            = info.Description,
                MaxAllowedGroupSize    = info.MaxAllowedGroupSize,
                MaxChildAge            = info.MaxChildAge,
                MaxTicketOrderInterval = info.MaxTicketOrderInterval,
                SightseeingDuration    = info.SightseeingDuration,
                OpeningHours           = new OpeningHoursDto[] { }
            };

            foreach (var openingHour in info.OpeningHours)
            {
                infoDto.OpeningHours.ToList().Add(new OpeningHoursDto
                {
                    OpeningHour = openingHour.OpeningHour,
                    ClosingHour = openingHour.ClosingHour,
                    DayOfWeek   = openingHour.DayOfWeek
                });
            }

            return(infoDto);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddInfoAsync([FromBody] VisitInfoDto info)
        {
            _logger.LogInformation($"Starting method '{nameof(AddInfoAsync)}'.");

            try
            {
                // Ignore Id if the client set it. Id of entity is set internally by the server.
                info.Id = null;

                var infoToBeAdded = MapToDomainModel(info);
                var addedInfo     = await _infoDbService.RestrictedAddAsync(infoToBeAdded);

                // Reverse map only for response to the client.
                var    addedInfoDto = MapToDto(addedInfo);
                var    response     = new ResponseWrapper(addedInfoDto);
                string addedInfoUrl = $"{ControllerPrefix}/{addedInfo.Id}";
                _logger.LogInformation($"Finished method '{nameof(addedInfo)}'.");
                return(Created(addedInfoUrl, response));
            }
            catch (InvalidOperationException ex)
            {
                return(OnInvalidParameterError($"Element '{typeof(VisitInfo).Name}' already exists.", ex));
            }
            catch (InternalDbServiceException ex)
            {
                LogInternalDbServiceException(ex, _infoDbService.GetType());
                throw;
            }
            catch (Exception ex)
            {
                LogUnexpectedException(ex);
                throw;
            }
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     _infoDbServiceMock = new Mock <IVisitInfoDbService>();
     _logger            = Mock.Of <ILogger <VisitInfoController> >();
     _mapperMock        = new Mock <IMapper>();
     _info     = CreateModel.CreateInfo();
     _infoDto  = CreateInfoDto(_info);
     _infoDtos = new VisitInfoDto[] { _infoDto };
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateInfoAsync(string id, [FromBody] VisitInfoDto info)
        {
            _logger.LogInformation($"Starting method '{nameof(UpdateInfoAsync)}'.");

            if (string.IsNullOrEmpty(id))
            {
                return(OnInvalidParameterError($"An argument '{nameof(id)}' cannot be null or empty."));
            }

            if (!id.Equals(info.Id))
            {
                return(OnMismatchParameterError($"An '{nameof(id)}' in URL end field '{nameof(info.Id).ToLower()}' in request body mismatches. Value in URL: '{id}'. Value in body: '{info.Id}'."));
            }

            try
            {
                var infoToBeUpdated = MapToDomainModel(info);
                var updatedInfo     = await _infoDbService.RestrictedUpdateAsync(infoToBeUpdated);

                // Revers map for client response.
                info = MapToDto(updatedInfo);
                var response = new ResponseWrapper(info);
                _logger.LogInformation($"Finished method '{nameof(UpdateInfoAsync)}'");
                return(Ok(response));
            }
            catch (InvalidOperationException ex)
            {
                return(OnNotFoundError($"Cannot found element '{typeof(VisitInfo).Name}' with specified id: '{id}'.", ex));
            }
            catch (InternalDbServiceException ex)
            {
                LogInternalDbServiceException(ex, _infoDbService.GetType());
                throw;
            }
            catch (Exception ex)
            {
                LogUnexpectedException(ex);
                throw;
            }
        }
Ejemplo n.º 5
0
 private VisitInfo MapToDomainModel(VisitInfoDto tariffDto) => _mapper.Map <VisitInfo>(tariffDto);