public void Create(HotelDTO item) { Hotel newHotel = toEntityMapper.Map <HotelDTO, Hotel>(item); database.Hotels.Create(newHotel); database.Save(); }
public async Task <IActionResult> PutHotel([FromRoute] int id, [FromBody] HotelDTO _hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != _hotel.Id) { return(BadRequest()); } Hotel hotel_map = Mapper.Map <Hotel>(_hotel); _context.Entry(hotel_map).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HotelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task CanCreateAndReturnHotelDTO() { // arrange var hotel = new Hotel { Name = "Mariott", City = "Seattle", StreetAddress = "Main Street", State = "WA", Phone = "8675309" }; var repo = BuildHotelRepo(); HotelDTO hotelDTO = new HotelDTO() { Id = hotel.Id, Name = hotel.Name, StreetAddress = hotel.StreetAddress, City = hotel.City, State = hotel.State, Phone = hotel.Phone }; // act var savedHotel = await repo.Create(hotelDTO); // assert Assert.NotNull(savedHotel); Assert.Equal(savedHotel.Id, hotel.Id); Assert.Equal(hotel.Name, savedHotel.Name); }
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 SetUp() { _repositoryMock = new Mock <IHotelRepository>(); _mapperMock = new Mock <IHotelModelMapper>(); _subject = new HotelService(_mapperMock.Object, _repositoryMock.Object); _dto1 = new HotelDTO { Id = 1, Name = "Testhotell 1", SingleRoomPrice = 11, DoubleRoomPrice = 12, TripleRoomPrice = 13, GroupRoomPrice = 14, ExtraBedPrice = 15, IsActive = true }; _dto2 = new HotelDTO { Id = 2, Name = "Testhotell 2", SingleRoomPrice = 21, DoubleRoomPrice = 22, TripleRoomPrice = 23, GroupRoomPrice = 24, ExtraBedPrice = 25, IsActive = true }; _dto3 = new HotelDTO { Id = 3, Name = "Testhotell 3", SingleRoomPrice = 31, DoubleRoomPrice = 32, TripleRoomPrice = 33, GroupRoomPrice = 34, ExtraBedPrice = 35, IsActive = true }; _model1 = new Hotel { Id = 1, Name = "Testhotell 1", SingleRoomPrice = 11, DoubleRoomPrice = 12, TripleRoomPrice = 13, GroupRoomPrice = 14, ExtraBedPrice = 15, IsActive = true }; _model2 = new Hotel { Id = 2, Name = "Testhotell 2", SingleRoomPrice = 21, DoubleRoomPrice = 22, TripleRoomPrice = 23, GroupRoomPrice = 24, ExtraBedPrice = 25, IsActive = true }; _model3 = new Hotel { Id = 3, Name = "Testhotell 3", SingleRoomPrice = 31, DoubleRoomPrice = 32, TripleRoomPrice = 33, GroupRoomPrice = 34, ExtraBedPrice = 35, IsActive = true }; }
/// <summary> /// Deletes a hotel from the Hotels database table, /// based on the hotel Id parameter. /// </summary> /// <param name="id">Unique identifier of the room</param> /// <returns>Task of completion</returns> public async Task Delete(int id) { HotelDTO hotelDto = await GetHotel(id); _context.Entry(hotelDto).State = EntityState.Deleted; await _context.SaveChangesAsync(); }
public async Task Delete(int id) { HotelDTO hotel = await GetHotel(id); _context.Entry(hotel).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; await _context.SaveChangesAsync(); }
public ActionResult DeleteConfirmed(Guid Id) { HotelDTO hotelDto = hotelService.GetHotelById(Id); hotelService.DeleteHotel(hotelDto); return(RedirectToAction("Index")); }
/// <summary> /// Updates the Hotel with the inputted information /// </summary> /// <param name="hotel">The Hotel to be updated</param> /// <returns>The updated Hotel</returns> public async Task <HotelDTO> Update(HotelDTO hotel) { _context.Entry(hotel).State = EntityState.Modified; await _context.SaveChangesAsync(); return(hotel); }
public async Task <HotelDTO> GetHotel(int id) { var hotel = await _context.Hotels.Where(x => x.ID == id) .Include(x => x.HotelRooms) .ThenInclude(x => x.Layout) .ThenInclude(x => x.RoomAmenities) .ThenInclude(x => x.Amenity) .FirstOrDefaultAsync(); HotelDTO hotelDTO = new HotelDTO() { ID = hotel.ID, Name = hotel.Name, StreetAddress = hotel.StreetAddress, City = hotel.City, State = hotel.State, PhoneNumber = hotel.PhoneNumber, HotelRooms = (List <HotelRoom>)hotel.HotelRooms }; return(hotelDTO); }
// Add a new hotel public void AddHotel(HotelDTO hotelDto) { Hotel hotel = Mapper.Map <HotelDTO, Hotel>(hotelDto); _unitOfWork.Hotels.Create(hotel); _unitOfWork.Save(); }
public async Task <HotelDTO> GetHotel(int id) { //look in the db on the hotel table where the id is //equal to the id that was brought in as an argument Hotel hotel = await _context.Hotels.FindAsync(id); var hotelRooms = await _context.Hotels.Where(x => x.Id == id) .Include(x => x.HotelRooms) .ThenInclude(x => x.Room) .ThenInclude(x => x.RoomAmenities) .ThenInclude(x => x.Amenity) .ToListAsync(); List <HotelRoomDTO> hotelRoom = new List <HotelRoomDTO>(); foreach (var item in hotelRoom) { hotelRoom.Add(new HotelRoomDTO { HotelId = item.HotelId, RoomNumber = item.RoomNumber }); } HotelDTO dto = new HotelDTO() { Id = hotel.Id, Name = hotel.Name, StreetAddress = hotel.StreetAddress, City = hotel.City, State = hotel.State, Phone = hotel.Phone, HotelRooms = hotelRoom, }; return(dto); }
/// <summary> /// gets a single hotel /// </summary> /// <param name="id">hotel identifier</param> /// <returns>task completion </returns> public async Task <HotelDTO> GetHotel(int id) { // looks into the db and finds the object with the same id Hotel hotel = await _context.Hotels.Where(x => x.Id == id) .Include(x => x.HotelRooms) .ThenInclude(x => x.room) .ThenInclude(x => x.RoomAmenities) .ThenInclude(x => x.amenity) .FirstOrDefaultAsync(); List <HotelRoomDTO> hotelroom = await _hotelroom.GetHotelRooms(id); HotelDTO hoteldto = new HotelDTO() { Name = hotel.Name, StreetAddress = hotel.StreetAddress, City = hotel.City, State = hotel.State, Phone = hotel.Phone, HotelRooms = hotelroom }; return(hoteldto); }
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 async Task <HotelDTO> Create(HotelDTO hotel) { _context.Entry(hotel).State = Microsoft.EntityFrameworkCore.EntityState.Added; await _context.SaveChangesAsync(); return(hotel); }
public Hotel() { InitializeComponent(); DTO = new HotelDTO(); sqlCon = new SqlConnection("Data Source=DESKTOP-63Q74F5;Initial Catalog=Project;Integrated Security=True"); cmd = new SqlCommand(); }
public void AddHotel(HotelDTO NewHotel) { if (UserLogic.CurrentUser == null || UserLogic.CurrentUser.UserType != DTOs.UserType.Manager) { throw new WrongUserException("Function availible only for managers"); } UoW.Hotels.Add(HotelLogicMapper.Map <HotelDTO, Hotel>(NewHotel)); }
// Delete hotel public void DeleteHotel(HotelDTO hotelDto) { Hotel hotel = Mapper.Map <HotelDTO, Hotel>(hotelDto); _unitOfWork.Hotels.Delete(hotel.Id); _unitOfWork. Save(); }
public JsonResult Delete(HotelDTO dto) { var manager = this.GetManagerFor <IHotelManager>(); var result = manager.Delete(dto.Id); var resultDTO = new HotelDTO(result); return(Json(resultDTO)); }
public JsonResult Update(HotelDTO dto) { var manager = this.GetManagerFor<IHotelManager>(); var result = manager.Update(dto); var resultDTO = new HotelDTO(result); return Json(resultDTO); }
public async Task <HotelDTO> GetHotel(int id) { HotelDTO hotel = await _context.Hotels .Where(h => h.Id == id) .Select(h => new HotelDTO() { Id = h.Id, Name = h.Name, StreetAddress = h.StreetAddress, City = h.City, State = h.State, Phone = h.Phone, Rooms = h.HotelRooms .Select(hr => new HotelRoomDTO() { HotelId = hr.HotelId, RoomId = hr.RoomId, RoomNumber = hr.RoomNumber, Rate = hr.Rate, PetFriendly = hr.PetFriendly, Room = hr.Room.HotelRooms .Select(r => new RoomDTO() { Id = r.Room.Id, Name = r.Room.Name, Layout = r.Room.Layout //Amenities = r.room.RoomAmenities // .Select(ra => new AmenityDTO() // { // Id = ra.amenity.Id, // Item = ra.amenity.Item // }).ToList() }).FirstOrDefault() }).ToList() }).FirstOrDefaultAsync(); //Hotel hotel = await _context.Hotels.FindAsync(id); //var hotelRooms = await _context.HotelRooms // .Where(x => x.HotelId == id) // .Include(x => x.room) // .ToListAsync(); //hotel.HotelRooms = hotelRooms; //foreach(var hotelRoom in hotel.Rooms) //{ // var ra = await _context.RoomAmenities; // .Where(ra => ra.RoomId == hotelRoom.RoomId) // .Select(a => new AmenityDTO() // { // Id = a.amenity.Id, // Item = a.amenity.Item // }) // .ToListAsync(); // hotelRoom.Room.Amenities = ra; //} return(hotel); }
public void ValidHotelDTOCommand_NoExceptionThrown() { Assert.DoesNotThrow(() => { HotelMapper _HotelMapper = MapperFactory.createHotelMapper(); HotelDTO result = _HotelMapper.CreateDTO(_hotel); HotelDTOValidatorCommand command = CommandFactory.HotelDTOValidatorCommand(result); command.Execute(); }); }
public async Task DeleteAsync(HotelDTO dto) { dto = dto ?? throw new ArgumentNullException(nameof(dto)); var model = _mapper.Map <Hotel>(dto); _dataContext.Hotels.Remove(model); await _dataContext.SaveChangesAsync(); }
async Task <HotelDTO> IService <HotelDTO, int> .Add(HotelDTO entity) { Hotel hotel = (await _hotelRepository.Get(prop => prop.Name == entity.Name)).FirstOrDefault(); if (hotel == null) { hotel = await _hotelRepository.Add(_mapper.Map <HotelDTO, Hotel>(entity)); } return(_mapper.Map <Hotel, HotelDTO>(hotel)); }
public async Task <IActionResult> PutHotel(int id, HotelDTO hotelDTO) { if (id != hotelDTO.Id) { return(BadRequest()); } HotelDTO updatedHotelDTO = await _hotel.Update(hotelDTO); return(Ok(updatedHotelDTO)); }
public async Task <IActionResult> AddHotel([FromBody] HotelDTO hotel) { if (ModelState.IsValid) { hotel = await _hotelService.Add(hotel); return(Ok(hotel)); } return(BadRequest(ModelState)); }
public IActionResult GetHotel(int id) { HotelDTO hotel = hotelAdminService.FindHotel(id); if (hotel is null) { return(NotFound()); } return(Ok(mapper.Map <HotelModel>(hotel))); }
public void CreateHotel(HotelDTO hotel) { Hotel newHotel = new Hotel() { Name = hotel.Name, Address = hotel.Address }; uow.Hotels.Create(newHotel); uow.Save(); }
public async Task <ActionResult <HotelDTO> > GetHotel(int id) { HotelDTO hotel = await hotelRepository.GetOneHotel(id); if (hotel == null) { return(NotFound()); } return(hotel); }
public ActionResult Create(HotelViewModel hotelViewModel) { if (ModelState.IsValid) { HotelDTO hotelDto = Mapper.Map <HotelViewModel, HotelDTO>(hotelViewModel); hotelDto.Id = Guid.NewGuid(); hotelService.AddHotel(hotelDto); return(RedirectToAction("Index")); } return(View(hotelViewModel)); }
public async Task <IActionResult> PutHotel(int id, HotelDTO hotel) { if (id != hotel.ID) { return(BadRequest()); } var updateHotel = await _hotel.Update(hotel); return(Ok(updateHotel)); }
public JsonResult GetHotel(int id, IEnumerable<string> query) { var queries = new Query[] { }; if (query != null) { queries = query.Select(q => new Query { Name = q }).ToArray(); } var manager = this.GetManagerFor<IHotelManager>(); var result = manager.GetById(id); var resultDTO = new HotelDTO(queries, result); return Json(resultDTO); }