// GET: Rooms public ActionResult Index(ReservationSearchModel model) { _types = _roomType.RetrieveAllRoomTypes(); roomManager = new RoomManager(); model.Rooms = roomManager.RetrieveRoomList(); int hour = DateTime.Now.Hour; ViewBag.Greeting = hour < 12 ? "Good Morning" : "Good Afternoon"; ViewBag.Types = _types; return(View(model)); }
public async Task <IActionResult> Details(int id, ReservationSearchModel searchModel) { var rental = await _gatewayService.Get <RentalViewModel>($"rentals/{id}"); var reservations = await _gatewayService .Get <IList <ReservationViewModel> >($"/rentals/{id}/reservations"); // filtering should be done on backend, not here. oh no... anyway IEnumerable <ReservationViewModel> filteredReservations = reservations.Content; if (!string.IsNullOrEmpty(searchModel.FromDate) && DateTime.TryParse(searchModel.FromDate, out var fromDate)) { filteredReservations = reservations.Content.Where(res => res.StartDateUtc >= fromDate); } if (!string.IsNullOrEmpty(searchModel.ToDate) && DateTime.TryParse(searchModel.ToDate, out var toDate)) { filteredReservations = reservations.Content.Where(res => res.EndDateUtc <= toDate); } var viewModel = new RentalDetailsViewModel { Details = rental.Content, Reservations = filteredReservations?.ToList() ?? new List <ReservationViewModel>() }; viewModel.ReservationSearchModel.FromDate = searchModel.FromDate; viewModel.ReservationSearchModel.ToDate = searchModel.ToDate; return(rental.IsSuccess ? View(viewModel) : RedirectToAction(nameof(Index)) .WithWarning("Oops!", rental.ErrorMessage)); }