Exemplo n.º 1
0
 BookingModel BookingModelToViewModel(Service.DTO.BookingModel bookingModel)
 {
     BookingModel bookingViewModel = new BookingModel() { CheckInDate = bookingModel.CheckInDate, CheckOutDate = bookingModel.CheckOutDate, Id = bookingModel.Id, Price = 0 };
     foreach (Service.DTO.RoomModel room in bookingModel.Rooms)
     {
         RoomCategory rc = bookingViewModel.RoomCategories.Where(r => r.CategoryId == room.TheCategory.Id).FirstOrDefault();
         if (rc == null) bookingViewModel.RoomCategories.Add(new RoomCategory() { CategoryId = room.TheCategory.Id, Description = room.TheCategory.Description, Name = room.TheCategory.Name, NumberOfRooms = 0 });
         bookingViewModel.RoomCategories.Where(cat => cat.CategoryId == room.TheCategory.Id).First().NumberOfRooms++;
     }
     return bookingViewModel;
 }
        //Show specific booking for logged in user
        public ActionResult MyBooking(int id)
        {
            Service.DTO.BookingModel bookingModel = bookingService.GetBooking(id);
            if (bookingModel == null) return RedirectToAction("MyBookings");
            if (bookingModel.UserId != User.Identity.GetUserId()) return RedirectToAction("MyBookings");

            BookingModel bookingViewModel = new BookingModel(bookingModel);

            return View(bookingViewModel);
        }