public JsonResult Update(string model) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } var codeModel = JsonConvert.DeserializeObject <MissingPropertyCodesModel>(model); try { var dataProvider = new ReservationRevenueProvider(_dbContext); var entity = dataProvider.Retrieve(codeModel.ReservationId); entity.PropertyCode = codeModel.PropertyCode; dataProvider.Update(codeModel.ReservationId, entity); dataProvider.Commit(); return(Json(codeModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Property Code for Reservation {0:d} fails. {1},{2}", codeModel.ReservationId, ex.Message, innerErrorMessage); return(InternalError(message, string.Empty, ex)); } }
public JsonResult DeleteRevenue(int id) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } try { var dataProvider = new ReservationRevenueProvider(_dbContext); var entity = dataProvider.Retrieve(id); dataProvider.Delete(id); dataProvider.Commit(); var provider = new OwnerPayoutProvider(_dbContext); provider.UpdateOwnerPayoutMatchStatus(entity.OwnerPayoutId); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { string message = string.Format("Delete Reservation {0} fails. {1}", id.ToString(), ex.Message + ex.StackTrace); return(InternalError(message, "fail", ex)); } }
public JsonResult SaveRevenue(ReservationRevenueModel form) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } try { // treat checkin and checkout date as Hawaii time zone and covert it to UTC by adding 11 hours. if (form.PayoutDate != null) { form.PayoutDate = ConversionHelper.ToUtcFromUs(form.PayoutDate.Value); } if (form.CheckinDate != null) { form.CheckinDate = ConversionHelper.ToUtcFromUs(form.CheckinDate.Value); } var dataProvider = new ReservationRevenueProvider(_dbContext); if (form.ReservationId == 0) // new reservation { if (dataProvider.GetKey(form) != 0) { Response.StatusCode = (int)System.Net.HttpStatusCode.Conflict; // code = 409 return(Json(string.Empty, JsonRequestBehavior.AllowGet)); } else { dataProvider.Create(form); } } else // updating reservation { dataProvider.Update(form.ReservationId, form); } dataProvider.Commit(); // ReservationId will be filled for new reservation by EF // get the reservation ID if (form.ReservationId == 0) { form.ReservationId = dataProvider.GetKey(form); } var provider = new OwnerPayoutProvider(_dbContext); provider.UpdateOwnerPayoutMatchStatus(form.OwnerPayoutId); return(Json(form.ReservationId.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Reservation {0} fails. {1},{2}", form.ReservationId.ToString(), ex.Message, innerErrorMessage); return(InternalError(message, string.Empty, ex)); } }
public JsonResult ConvertRevenue(int id) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } try { var reservationProvider = new ReservationRevenueProvider(_dbContext); var entity = reservationProvider.Retrieve(id); // create resolution entity var resolutionModel = new ResolutionRevenueModel(); resolutionModel.ResolutionDate = entity.PayoutDate; resolutionModel.OwnerPayoutId = entity.OwnerPayoutId; resolutionModel.ConfirmationCode = entity.ConfirmationCode; resolutionModel.PropertyCode = entity.PropertyCode; resolutionModel.ResolutionType = "Cancellation"; resolutionModel.ResolutionDescription = "Converted from Reservation"; resolutionModel.ResolutionAmount = entity.TotalRevenue; resolutionModel.IncludeOnStatement = true; resolutionModel.Impact = string.Empty; resolutionModel.ApprovalStatus = RevenueApprovalStatus.NotStarted; var resolutionProvider = new ResolutionRevenueProvider(_dbContext); resolutionProvider.Create(resolutionModel); resolutionProvider.Commit(); // set reservation revenue to 0 and excluded from statement entity.TotalRevenue = 0; entity.IncludeOnStatement = false; reservationProvider.Update(id, entity); reservationProvider.Commit(); var provider = new OwnerPayoutProvider(_dbContext); provider.UpdateOwnerPayoutMatchStatus(entity.OwnerPayoutId); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { string message = string.Format("Delete Reservation {0} fails. {1}", id.ToString(), ex.Message + ex.StackTrace); return(InternalError(message, "fail", ex)); } }
public JsonResult SaveNote(int id, string note) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } try { var dataProvider = new ReservationRevenueProvider(_dbContext); var entity = dataProvider.Retrieve(id); entity.ApprovedNote = note; dataProvider.Update(id, entity); dataProvider.Commit(); return(Json(id.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Reservation {0:d} fails. {1},{2}", id, ex.Message, innerErrorMessage); return(InternalError(message, string.Empty, ex)); } }
public JsonResult ChangePropertyCode(ResevationTetrisModel form) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } try { var dataProvider = new ReservationRevenueProvider(_dbContext); var entity = dataProvider.Retrieve(form.ReservationId); entity.PropertyCode = form.NewPropertyCode; dataProvider.Update(form.ReservationId, entity); dataProvider.Commit(); return(Json(form.ReservationId.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Changing Reservation {0:d} property code to {1} fails. {2},{3}", form.ReservationId, form.NewPropertyCode, ex.Message, innerErrorMessage); return(InternalError(message, string.Empty, ex)); } }