public JsonResult Create(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model); try { var entity = new PropertyFee(); var dataProvider = new PropertyFeeProvider(_dbContext); dataProvider.MapData(feeModel, ref entity); dataProvider.Create(entity); dataProvider.Commit(); feeModel.PropertyFeeId = entity.PropertyCostId; // set the created Id to return to kendo grid return(Json(feeModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Creating Property Fee fails. {0} - {1}", ex.Message, innerErrorMessage); return(InternalError(message, string.Empty)); } }
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 feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model); try { var dataProvider = new PropertyFeeProvider(_dbContext); var entity = dataProvider.Retrieve(feeModel.PropertyFeeId); dataProvider.MapData(feeModel, ref entity); dataProvider.Update(entity.PropertyCostId, entity); dataProvider.Commit(); return(Json(feeModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Property Fee {0:d} fails. {1} - {2}", feeModel.PropertyFeeId, ex.Message, innerErrorMessage); return(InternalError(message, "fail", ex)); } }
public JsonResult Delete(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model); try { var dataProvider = new PropertyFeeProvider(_dbContext); dataProvider.Delete(feeModel.PropertyFeeId); dataProvider.Commit(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(InternalError(string.Format("Delete Property Fee {0:d} fails.", feeModel.PropertyFeeId), "fail", ex)); } }