public JsonResult Update(string model) // parameter must be the same json object defined in parameterMap in kendo's datab source { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var titleModel = JsonConvert.DeserializeObject <PropertyTitleHistoryRow>(model); try { var dataProvider = new PropertyTitleHistoryProvider(_dbContext); var entity = dataProvider.Retrieve(titleModel.PropertyTitleHistoryId); entity.PropertyCode = titleModel.PropertyCode; entity.PropertyTitle = titleModel.PropertyTitle.Substring(0, Math.Min(200, titleModel.PropertyTitle.Length)); entity.EffectiveDate = ConversionHelper.EnsureUtcDate(titleModel.EffectiveDate); dataProvider.Update(entity.PropertyTitleHistoryId, entity); dataProvider.Commit(); return(Json(titleModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Property Title {0:d} fails. {1} - {2}", titleModel.PropertyTitleHistoryId, ex.Message, innerErrorMessage); return(InternalError(message, "fail", ex)); } }
public JsonResult Create(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var titleModel = JsonConvert.DeserializeObject <PropertyTitleHistoryRow>(model); try { PropertyTitleHistory titleHistory = new PropertyTitleHistory(); var dataProvider = new PropertyTitleHistoryProvider(_dbContext); titleHistory.PropertyCode = titleModel.PropertyCode; titleHistory.PropertyTitle = titleModel.PropertyTitle.Substring(0, Math.Min(200, titleModel.PropertyTitle.Length)); titleHistory.EffectiveDate = ConversionHelper.EnsureUtcDate(titleModel.EffectiveDate); dataProvider.Create(titleHistory); dataProvider.Commit(); return(Json(titleModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Creating Property Title fails. {0} - {1}", ex.Message, innerErrorMessage); return(InternalError(message, string.Empty)); } }
public JsonResult Delete(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var titleModel = JsonConvert.DeserializeObject <PropertyTitleHistory>(model); try { var dataProvider = new PropertyTitleHistoryProvider(_dbContext); dataProvider.Delete(titleModel.PropertyTitleHistoryId); dataProvider.Commit(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(InternalError(string.Format("Delete Property Title {0:d} fails.", titleModel.PropertyTitleHistoryId), "fail", ex)); } }
public JsonResult ModalEdit(CPL form) { if (!AuthorizationProvider.IsPropertyEditor()) { return(Json("denied", JsonRequestBehavior.AllowGet)); } try { if (ModelState.IsValid) { PropertyProvider dataProvider = new PropertyProvider(_dbContext); // make the date to PST time zone to store in DB using UTC if (form.ListingStartDate != null) { form.ListingStartDate = form.ListingStartDate.Value.Date.AddHours(11); } if (form.PendingContractDate != null) { form.PendingContractDate = form.PendingContractDate.Value.Date.AddHours(11); } if (form.PendingOnboardingDate != null) { form.PendingOnboardingDate = form.PendingOnboardingDate.Value.Date.AddHours(11); } bool managementFeeChanged = false; bool titleChanged = false; if (!dataProvider.PropertyExist(form.PropertyCode)) // new property { titleChanged = true; managementFeeChanged = true; form.PropertyCode = form.PropertyCode.ToUpper(); // if entity state is EntityState.UnAttached, CreatedDate won't be created. we set it explicitly here just to be sure form.CreatedDate = ConversionHelper.EnsureUtcDate(DateTime.Now.Date); form.CreatedBy = ClaimsPrincipal.Current.Identity.Name; dataProvider.Create(form); } else // updating property { var property = dataProvider.Retrieve(form.PropertyCode); if (property != null) { titleChanged = string.Compare(property.AirBnBHomeName, form.AirBnBHomeName, true) != 0; managementFeeChanged = property.Ownership != form.Ownership; if (string.Compare(property.PropertyStatus, form.PropertyStatus, true) != 0) { setInactiveTimestamp(form); } dataProvider.Update(form.PropertyCode, form); } } dataProvider.Commit(); // update PropertyTitleHistory table if title has changed if (titleChanged) { var titleProvider = new PropertyTitleHistoryProvider(_dbContext); if (!titleProvider.Exist(form.PropertyCode, form.AirBnBHomeName)) { var titleHistory = new PropertyTitleHistory() { PropertyCode = form.PropertyCode, PropertyTitle = form.AirBnBHomeName, EffectiveDate = ConversionHelper.EnsureUtcDate(DateTime.UtcNow) }; titleProvider.Create(titleHistory); titleProvider.Commit(); } } // obsolete: Property fee has moved to property fee table if (managementFeeChanged) { // TODO: add a record to PropertyFee table for new management fee } ViewBag.Accounts = (new AirbnbAccountProvider(_dbContext)).AggregatedAccounts(); return(Json(form.PropertyCode, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { // TODO: log this.ModelState.AddModelError("", ex); } return(Json(string.Empty, JsonRequestBehavior.AllowGet)); }