public ActionResult <HotelDTO> Create([FromBody] HotelDTO hotelDTO) { try { HotelMapper hotelMapper = MapperFactory.createHotelMapper(); Entity entity = hotelMapper.CreateEntity(hotelDTO); AddHotelCommand command = CommandFactory.createAddHotelCommand((Hotel)entity); command.Execute(); int idFromData = command.GetResult(); _logger?.LogInformation($"Obtenido el id = {idFromData} el Hotel exitosamente al agregar"); GetHotelByIdCommand commandId = CommandFactory.GetHotelByIdCommand(idFromData); commandId.Execute(); var result = commandId.GetResult(); _logger?.LogInformation($"Obtenido el hotel exitosamente por Id = {idFromData}"); DTO lDTO = hotelMapper.CreateDTO(result); return(CreatedAtAction("Get", "hotels", lDTO)); } catch (RequiredAttributeException e) { _logger?.LogWarning($"Atributo requerido no recibido al agregar Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } catch (InvalidAttributeException e) { _logger?.LogWarning($"Valor del atributo es invalido al agregar Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } }
public ActionResult <HotelDTO> Update([FromRoute] int hotelId, [FromBody] HotelDTO hotelDTO) { try { GetHotelByIdCommand commandId = CommandFactory.GetHotelByIdCommand(hotelId); commandId.Execute(); HotelMapper hotelMapper = MapperFactory.createHotelMapper(); Entity entity = hotelMapper.CreateEntity(hotelDTO); UpdateHotelCommand command = CommandFactory.UpdateHotelCommand(hotelId, (Hotel)entity); command.Execute(); var result = command.GetResult(); _logger?.LogInformation($"Obtenido el hotel exitosamente, despues de actualizar con el Id = {hotelId}"); DTO lDTO = hotelMapper.CreateDTO(result); return(Ok(lDTO)); } catch (HotelNotFoundException ex) { _logger?.LogWarning("Hotel con id = {hotelId} no conseguido al intentar actualizar"); return(new NotFoundObjectResult(new ErrorMessage($"Hotel con id {hotelId} no conseguido"))); } catch (RequiredAttributeException e) { _logger?.LogWarning($"El atributo requerido no fue recibido al actualizar el Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } catch (InvalidAttributeException e) { _logger?.LogWarning($"El valor del atributo es invalido al actualizar el Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } }
public void CreateDTOTest() { HotelMapper _HotelMapper = MapperFactory.createHotelMapper(); var result = _HotelMapper.CreateDTO(_hotel); Assert.IsInstanceOf <HotelDTO>(result); }
public void ValidHotelDTOCommand_NoExceptionThrown() { Assert.DoesNotThrow(() => { HotelMapper _HotelMapper = MapperFactory.createHotelMapper(); HotelDTO result = _HotelMapper.CreateDTO(_hotel); HotelDTOValidatorCommand command = CommandFactory.HotelDTOValidatorCommand(result); command.Execute(); }); }
public void ValidHotelDTOCommand_LocationExceptionThrown() { Assert.Throws <RequiredAttributeException>(() => { HotelMapper _HotelMapper = MapperFactory.createHotelMapper(); HotelDTO result = _HotelMapper.CreateDTO(_hotel); result.Location = null; HotelDTOValidatorCommand command = CommandFactory.HotelDTOValidatorCommand(result); command.Execute(); }); }
public ActionResult <HotelDTO> GetById([FromRoute] int hotelId) { try { HotelMapper hotelMapper = MapperFactory.createHotelMapper(); GetHotelByIdCommand commandId = CommandFactory.GetHotelByIdCommand(hotelId); commandId.Execute(); var result = commandId.GetResult(); _logger?.LogInformation($"Obtenido el hotel exitosamente por Id = {hotelId}"); DTO lDTO = hotelMapper.CreateDTO(result); return(Ok(lDTO)); } catch (HotelNotFoundException ex) { _logger?.LogWarning($"Hotel con Id = {hotelId} no conseguido al consultar"); return(NotFound()); } }
public void Setup() { _hotelsController = new HotelsController(null); _insertedHotels = new List <int>(); _hotelentity = HotelBuilder.Create() .WithName("Hotel Cagua") .WithAmountOfRooms(2000) .WithCapacityPerRoom(2) .WithPricePerRoom(200) .WithPhone("04243240208") .WithWebsite("HC.com") .WithStars(2) .LocatedAt(HotelTestSetup.LOCATION_ID) .WithStatus(true) .WithAddressDescription("Calle Los Almendrones") .WithPictureUrl("alguncodigoenbase64") .Build(); HotelMapper _HotelMapper = MapperFactory.createHotelMapper(); _hotel = _HotelMapper.CreateDTO(_hotelentity); }