public ActionResult Edit(int Id) { if (!AuthorizationProvider.IsInquiryEditor() && !AuthorizationProvider.IsViewer()) { string message = string.Format("User '{0}' does not have permission to edit Inquiry {1}.", this.User.Identity.Name, Id.ToString()); DojoLogger.Warn(message, typeof(InquiryController)); return(RedirectToAction("Index", "Inquiry") .WithError("It looks like you do not have permisssion to edit this inquiry.")); } try { ViewBag.Title = "Edit Inquiry"; ViewBag.ButtonText = "Update Inquiry"; InquiryProvider inquiryProvider = new InquiryProvider(_dbContext); PropertyProvider propertyProvider = new PropertyProvider(_dbContext); InquiriesValidation inquiry = inquiryProvider.Retrieve(Id); if (inquiry == null) { return(RedirectToAction("NotFound", "Error")); } ViewBag.Properties = propertyProvider.AggregatedProperties(); return(PartialView("EditPartial", inquiry)); } catch (Exception ex) { string message = string.Format("Retrieve Inquiry {0} for Editing fails. {1}", Id.ToString(), ex.Message + ex.StackTrace); DojoLogger.Error(message, typeof(InquiryController)); } return(RedirectToAction("Index", "Inquiry") .WithError("The inquiry item cannot be found.")); }
public JsonResult Save(InquiriesValidation form) { if (!AuthorizationProvider.IsInquiryEditor()) { string message = string.Format("User '{0}' does not have permission to save Inquiry {1}.", this.User.Identity.Name, form.Id.ToString()); DojoLogger.Warn(message, typeof(InquiryController)); return(Json("denied", JsonRequestBehavior.AllowGet)); } try { // treat checkin and checkout date as Hawaii time zone and covert it to UTC by adding 11 hours. if (form.Check_inDate != null) { form.Check_inDate = form.Check_inDate.Value.Date.AddHours(11); } if (form.Check_outDate != null) { form.Check_outDate = form.Check_outDate.Value.Date.AddHours(11); } InquiryProvider inquiryProvider = new InquiryProvider(_dbContext); string message = string.Format("saving inquiry: name: {0} team: {1} property: {2} checkin: {3} checkout: {4} payout: {5}", form.GuestName, form.InquiryTeam, (!string.IsNullOrEmpty(form.PropertyCode) ? form.PropertyCode : "Invalid"), (form.Check_inDate != null ? form.Check_inDate.Value.ToShortDateString() : "Invalid"), (form.Check_outDate != null ? form.Check_outDate.Value.ToShortDateString() : "Invalid"), (form.TotalPayout != null ? form.TotalPayout.Value.ToString() : "Invalid")); DojoLogger.Trace(message, typeof(InquiryController)); if (form.Id == 0) // new inquiry { if (inquiryProvider.Exist(form.PropertyCode, form.GuestName, form.Check_inDate.Value, form.Check_outDate.Value)) { Response.StatusCode = (int)System.Net.HttpStatusCode.Conflict; // code = 409 return(Json(string.Empty, JsonRequestBehavior.AllowGet)); } else { SetRelatedFields(form); inquiryProvider.Create(form); } } else // updating inquiry { InquiriesValidation inquiry = inquiryProvider.Retrieve(form.Id); SetRelatedFields(inquiry, form); // need to set CreatedBy and CreatedDate a they are not part of form form.CreatedDate = inquiry.CreatedDate; form.CreatedBy = inquiry.CreatedBy; inquiryProvider.Update(inquiry.Id, inquiry); } inquiryProvider.Commit(); // Id will be filled for new inquiry by EF PropertyProvider propertyProvider = new PropertyProvider(_dbContext); ViewBag.Properties = propertyProvider.AggregatedProperties(); return(Json(form.Id.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { string message = string.Format("Saving Inquiry {0} fails. {1}", form.Id.ToString(), ex.Message); DojoLogger.Error(message, typeof(InquiryController)); Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; return(Json(string.Empty, JsonRequestBehavior.AllowGet)); } }