public ActionResult UpdateFacilityReservation(string selectedFacResId, string selectedGusResID) { // 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); } } // This is to filter out unrelated record, only return the selected records FacilityReservation selectedID = _facilityReservationService.RetrieveByReservationId(int.Parse(selectedFacResId)); Dictionary <string, string> currentRecord = new Dictionary <string, string>(); currentRecord.Add("FacilityId", selectedID.FacilityIdDetails().ToString()); currentRecord.Add("ReservationId", selectedID.ReservationIdDetails().ToString()); currentRecord.Add("ReserveeId", selectedID.ReserveeIdDetails().ToString()); currentRecord.Add("StartTime", selectedID.StartTimeDetails().ToString("yyyy-MM-dd")); currentRecord.Add("EndTime", selectedID.EndTimeDetails().ToString("yyyy-MM-ddTHH:mm")); currentRecord.Add("Pax", selectedID.NumberOfPax().ToString()); currentRecord.Add("SGID", selectedGusResID); currentRecord.Add("SFID", selectedFacResId); // Retrieve all existing guests Guest guestList = _guestService.SearchByGuestId(int.Parse(selectedGusResID)); // For loop to store existing guest to populate View Form DropDownList Dictionary <int, string> existguestList = new Dictionary <int, string>(); existguestList.Add(guestList.GuestIdDetails(), guestList.FirstNameDetails() + " " + guestList.LastNameDetails()); // Passing data over to View Page via ViewBag ViewBag.currentRecord = currentRecord; ViewBag.existguestList = existguestList; ViewBag.namefacilityList = namefacilityList; return(View()); }
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); } }