public ActionResult Search(SearchInputModel model) { if (!ModelState.IsValid) { return(View(model)); } if (model.StartDate.Date >= model.EndDate.Date) { return(RedirectToAction("Error", "Reservation", new ErrorViewModel { ErrorMsg = "start date must be before end date" })); } if (model.StartDate.Date < DateTimeHandler.GetCurrentDate()) { return(RedirectToAction("Error", "Reservation", new ErrorViewModel { ErrorMsg = "Start date must not be before today" })); } ViewBag.NoResult = false; var startDate = model.StartDate.GetStartDateTime(); var endDate = model.EndDate.Date.GetEndDateTime(); var availableRooms = new List <RoomPriceDetail>(); foreach (ROOM_TYPE type in Enum.GetValues(typeof(ROOM_TYPE))) { if (_roomHandler.IsAvailable(type, startDate, endDate)) { availableRooms.Add(GetPriceDetails(startDate, endDate, type)); } } if (availableRooms.Count <= 0) { return(RedirectToAction("Error", "Reservation", new ErrorViewModel { ErrorMsg = "No available room, please search again" })); } var sessionId = Guid.NewGuid().ToString(); ReservationHandler.SearchResultPool[sessionId] = new RoomSearchResultModel { SessionId = sessionId, Expiration = DateTimeHandler.GetCurrentTime().AddMinutes(10), RoomPriceDetails = availableRooms }; return(RedirectToAction("Result", "Reservation", new { SessionId = sessionId })); }
public async Task <ActionResult> ModifyRoomInventory(ROOM_TYPE?type, int?inventory) { ViewBag.Inventory = GetInventory(DateTimeHandler.GetCurrentDate()); if (type != null && inventory != null) { try { _roomHandler.UpdateRoomInventory((ROOM_TYPE)type, (int)inventory); return(RedirectToAction("Index")); } catch (ArgumentOutOfRangeException useless) { ViewBag.Status = "Unsuccessful! The new inventory value is invalid."; } } return(View()); }