public void ReservationRoomBuilder(string roomType, int noOfGuest, string promo) { if (_reservationValidator.ValidateRoomType(roomType)) { _reservation.SetReservationItem("RoomType", roomType); } else { _flag = false; _error = "ERROR: Invalid Room Type Input!"; } // Check if there is a Promo Code given if (promo != "") { // Check if the Promo Code given is valid if (_reservationValidator.ValidatePromo(promo)) { _reservation.SetReservationItem("Promo", promo); _reservation.SetReservationItem("Price", _reservationValidator.GetDiscountPrice(roomType, _days, promo)); } else { _flag = false; _error = "ERROR: Invalid Promo Code!"; } } else { _reservation.SetReservationItem("Promo", promo); _reservation.SetReservationItem("Price", _reservationValidator.GetRoomPrice(roomType, _days)); } // Check if Number of Guest does not exceed the Room Capacity or is below 0 if (_reservationValidator.RoomTypeToGuestNum(roomType, noOfGuest)) { _reservation.SetReservationItem("NoOfGuest", noOfGuest); } else { _flag = false; _error = "ERROR: Room type:" + roomType + " cannot fit " + noOfGuest + " guests!"; } }
public IActionResult UpdateReservation(IFormCollection resForm) { // Retrieving POST Data and initialise variables var resId = Convert.ToInt32(resForm["resID"]); var pax = Convert.ToInt32(resForm["Number of Guests"]); var roomType = resForm["Room Type"]; var startDate = Convert.ToDateTime(resForm["Check-In Date/Time"]); var endDate = Convert.ToDateTime(resForm["Check-Out Date/Time"]); var remarks = resForm["Remarks"]; var modifiedDate = DateTime.Now; var promoCode = resForm["PromoCode"]; var status = resForm["Status"]; var secretPin = resForm["PIN"]; var numOfDays = _reservationValidator.NumOfDays(startDate, endDate); // Check if Manager Secret Pin is correct if (_authenticate.AuthenticatePin(secretPin)) { var reservationPrice = 0.0; // Check if cancellation fee is required if (status == "Cancelled") { if (_reservationValidator.CheckCancellationFee(DateTime.Now, startDate)) { // Cancellation fee is 90% of reserved price double price = Convert.ToDouble( _reservationService.SearchByReservationId(resId).GetReservation()["InitialResPrice"]) * 0.9; // Calling Mod 2 Team 7 Service to notify of cancellation fee _iReservationInvoice.notifyCancellation(resId, Convert.ToDecimal(price)); } } // Check if reservation is able to be deleted if (resForm["submit"].ToString() == "Delete") { // retrieve current status of the reservation string checkStatus = _reservationService.SearchByReservationId(resId).GetReservation()["status"] .ToString(); // check if reservation status is cancelled if user is trying to delete if (checkStatus == "Cancelled") { _reservationService.DeleteReservation(resId); TempData["Message"] = "Record has been deleted"; return(RedirectToAction("ReservationView", "Reservation")); } // Error Msg TempData["Message"] = "Invalid Access to delete Reservation Record!"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } // Validate Num of Guest against Room Type Capacity if (!_reservationValidator.RoomTypeToGuestNum(roomType, pax)) { TempData["Message"] = "ERROR: " + roomType + " room is unable to hold " + pax + " guests!"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } // Validate Reservation Dates int dateFlag = _reservationValidator.CheckDates(startDate, endDate); if (dateFlag == 1) { TempData["Message"] = "ERROR: Start Date is more than End Date"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } if (dateFlag == 2) { TempData["Message"] = "ERROR: Current Date is more than Start Date"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } // Check if there is a Promo Code given if (promoCode != "") { // Check if the Promo Code given is valid if (_reservationValidator.ValidatePromo(promoCode)) { // set discounted price reservationPrice = _reservationValidator.GetDiscountPrice(roomType, numOfDays, promoCode); } else { // Promo code given in Invalid TempData["CreateReservationMsg"] = "Invalid Promo Code"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } } else { // set original price reservationPrice = _reservationValidator.GetRoomPrice(roomType, numOfDays); } // Update Database _reservationService.UpdateReservation(resId, pax, roomType, startDate, endDate, remarks, modifiedDate, promoCode, reservationPrice, status); // Success Message TempData["Message"] = "Status updated Successfully"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); } // Error - invalid duty manager pin TempData["Message"] = "ERROR: Invalid Duty Manager pin!"; return(RedirectToAction("UpdateReservation", "ReservationManagement", new { resID = resId })); }