public ActionResult UpdateGuest(IFormCollection form) { string guestID = form["guestID"]; int guestid = Convert.ToInt32(guestID); string firstName = form["FirstName"]; string lastName = form["LastName"]; string guestType = form["GuestType"]; string email = form["Email"]; string passportNumber = form["PassportNumber"]; string secretPin = form["secretpin"]; if (_authenticator.AuthenticatePin(secretPin) && Update(guestid, firstName, lastName, guestType, email, passportNumber)) { TempData["UpdateGuestMessage"] = "Success"; return(Redirect("/Guest")); } else { ViewData["UpdateGuestMessage"] = "Error"; Guest guest = _guestService.SearchByGuestId(guestid); GuestViewModel guestViewModel = (new GuestViewModel(guest.GuestIdDetails(), guest.FirstNameDetails(), guest.LastNameDetails(), guest.GuestTypeDetails(), guest.EmailDetails(), guest.PassportNumberDetails())); ViewBag.guest = guestViewModel; return(View()); } }
public ActionResult UpdateFacilityReservation(IFormCollection form) { // This is to retrieve the data from FORM string decision = form["submit"].ToString(); int reservationId = int.Parse(form["reservationId"]); int facilityPax = int.Parse(form["pax"]); DateTime endTime = Convert.ToDateTime(form["endTime"]); string hourSelect = form["hourSelected"]; //[0]: hour, [1]: number of pax string[] hourandpax = hourSelect.Split(","); DateTime startTime = Convert.ToDateTime(form["startTime"]); string secretPin = form["secretpin"]; int hourSelected = int.Parse(hourandpax[0]); int year = startTime.Year; int month = startTime.Month; int day = startTime.Day; int hour = hourSelected; int minutes = 00; String format = "AM"; DateTime Rdatetime = new DateTime(year, month, day, (format.ToUpperInvariant() == "PM" && hour < 12) ? hour + 12 : hour, minutes, 00); if (facilityPax <= int.Parse(hourandpax[1])) { // This is to update reservation // This is success scenario if (_authenticator.AuthenticatePin(secretPin) && Update(reservationId, Rdatetime, endTime, facilityPax)) { TempData["Message"] = "Updated"; // This required to change to facilityReservation landing page. return(RedirectToAction("Index", "FacilityReservation")); } else { TempData["Message"] = "Update Unsuccessful"; return(RedirectToAction("UpdateFacilityReservation", "FacilityReservation", new { selectedFacResId = form["selectedFacResId"], selectedGusResID = form["selectedGusResID"] }, null)); } } else { TempData["Message"] = "Update Unsuccessful due to over number of pax"; return(RedirectToAction("UpdateFacilityReservation", "FacilityReservation", new { selectedFacResId = form["selectedFacResId"], selectedGusResID = form["selectedGusResID"] }, null)); } }
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 })); }