public ActionResult Create(HotelReservationViewModel hotelReservationViewModel) { if (ModelState.IsValid) { try { HotelReservationDTO newReservation = new HotelReservationDTO() { ClientName = User.Identity.Name, StartDate = hotelReservationViewModel.StartDate, EndDate = hotelReservationViewModel.EndDate, Hotel = hotelService.FindById(hotelReservationViewModel.HotelId), NumberOfPersons = hotelReservationViewModel.NumberOfPersons }; hotelReservationService.Reserve(newReservation); return(RedirectToAction("Index", "Hotel")); } catch (Exception e) { ModelState.AddModelError("", e.Message); } } return(View(hotelReservationViewModel)); }
public void Reserve(HotelReservationDTO reservation) { HotelReservation newReservation = new HotelReservation() { ClientName = reservation.ClientName, Hotel = uow.Hotels.FindById(reservation.Hotel.Id), NumberOfPersons = reservation.NumberOfPersons, StartDate = reservation.StartDate, EndDate = reservation.EndDate }; uow.HotelReservations.Create(newReservation); uow.Save(); }
public void FindByIdTest() { ResetData(); var uow = new Mock <UnitOfWork>(); HotelReservationService hrs = new HotelReservationService(uow.Object); HotelReservation reservation = uow.Object.HotelReservations.Get()[uow.Object.HotelReservations.Get().Count - 1]; HotelReservationDTO res = hrs.FindById(reservation.HotelReservationId); Assert.AreEqual(reservation.ClientName, res.ClientName); Assert.AreEqual(reservation.Hotel.Name, res.Hotel.Name); Assert.AreEqual(reservation.StartDate, res.StartDate); Assert.AreEqual(reservation.EndDate, res.EndDate); }
public void ReserveTest() { ResetData(); var uow = new Mock <UnitOfWork>(); HotelReservationService hrs = new HotelReservationService(uow.Object); int numEx = uow.Object.HotelReservations.Get().Count + 1; HotelReservationDTO reservation = new HotelReservationDTO() { NumberOfPersons = 2, ClientName = "ewf", Hotel = Mapper.Map <HotelDTO>(uow.Object.Hotels.Get()[0]), StartDate = DateTime.Now, EndDate = DateTime.Now }; hrs.Reserve(reservation); Assert.AreEqual(numEx, uow.Object.HotelReservations.Get().Count); }