public ActionResult Index() { // Retrieve all facility based on Mod 3 Team 06 function List <PublicAreaDTO> fullfacilityList = _publicArea.getAllFacilityResults(); // For loop to store existing facility to populate View Form DropDownList Dictionary <int, string> namefacilityList = new Dictionary <int, string>(); if (fullfacilityList.Count > 0) { foreach (PublicAreaDTO fac in fullfacilityList) { namefacilityList.Add(fac.public_area_id, fac.public_area_name); } } // Retrieve all existing guests IEnumerable <Guest> guestList = _guestService.RetrieveGuests(); // For loop to store existing guest to populate View Form DropDownList Dictionary <int, string> existguestList = new Dictionary <int, string>(); foreach (var guest in guestList) { existguestList.Add(guest.GuestIdDetails(), guest.FirstNameDetails() + " " + guest.LastNameDetails()); } // Passing data over to View Page via ViewBag ViewBag.namefacilityList = namefacilityList; ViewBag.existguestList = existguestList; IEnumerable <FacilityReservationViewModel> facilityReservationList = GetAll(); return(View(facilityReservationList)); }
public bool CheckValidReservation(FacilityReservation facilityReservation) { int currentPax = 0; int maxPax = 0; // get max pax of facility List <PublicAreaDTO> fullfacilityList = _publicArea.getAllFacilityResults(); foreach (PublicAreaDTO fac in fullfacilityList) { if (fac.public_area_id == facilityReservation.FacilityIdDetails()) { maxPax = fac.max_pax; } } // get current number of pax of facility in timeslot IEnumerable <FacilityReservation> facilityReservations = RetrieveReservations(); foreach (FacilityReservation facilityReservationInDB in facilityReservations) { if (facilityReservationInDB.FacilityIdDetails() == facilityReservation.FacilityIdDetails()) { // check if same timeslot if ((DateTime.Compare(facilityReservation.StartTimeDetails(), facilityReservationInDB.EndTimeDetails()) <= 0) && (DateTime.Compare(facilityReservation.EndTimeDetails(), facilityReservationInDB.StartTimeDetails()) >= 0)) { currentPax += facilityReservationInDB.NumberOfPax(); } } } // sum up total pax if including new reservation int totalPax = currentPax + facilityReservation.NumberOfPax(); // check if exceed max pax if (totalPax > maxPax) { return(false); } else { return(true); } }