public JsonResult Create(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var payoutMethodModel = JsonConvert.DeserializeObject <PayoutMethodViewModel>(model); try { var dataProvider = new PayoutMethodProvider(_dbContext); PayoutMethod entity = new PayoutMethod(); dataProvider.MapData(payoutMethodModel, ref entity); dataProvider.Create(entity); dataProvider.Commit(); payoutMethodModel.PayoutMethodId = entity.PayoutMethodId; // set the created Id to return to kendo grid foreach (var m in payoutMethodModel.SelectedPropertyCodes) { _dbContext.PropertyPayoutMethods.Add(new PropertyPayoutMethod { PayoutMethodId = entity.PayoutMethodId, PropertyCode = m.Value, }); } dataProvider.Commit(); return(Json(payoutMethodModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Expense {0:d} fails. {1} - {2}", 0, 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 datasource { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var clientModel = JsonConvert.DeserializeObject <PayoutMethodViewModel>(model); try { var dataProvider = new PayoutMethodProvider(_dbContext); PayoutMethod entity = dataProvider.Retrieve(clientModel.PayoutMethodId); dataProvider.MapData(clientModel, ref entity); dataProvider.Update(entity.PayoutMethodId, entity); // update properties if changed var propertyToUpdate = dataProvider.PropertyToUpdate(entity.PayoutMethodId, clientModel.SelectedPropertyCodes); if (propertyToUpdate != null) { _dbContext.PropertyPayoutMethods.RemoveRange(propertyToUpdate); foreach (var newProperty in clientModel.SelectedPropertyCodes) { _dbContext.PropertyPayoutMethods.Add(new PropertyPayoutMethod { PropertyCode = newProperty.Value, PayoutMethodId = entity.PayoutMethodId }); } } dataProvider.Commit(); return(Json(clientModel, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; string message = string.Format("Saving Expense {0:d} fails. {1} - {2}", 0, ex.Message, innerErrorMessage); return(InternalError(message, "fail", ex)); } }
public JsonResult Delete(string model) { if (!AuthorizationProvider.IsStatementAdmin()) { return(Forbidden()); } var entity = JsonConvert.DeserializeObject <PayoutMethodViewModel>(model); try { var dataProvider = new PayoutMethodProvider(_dbContext); dataProvider.Delete(entity.PayoutMethodId); // will do cascade deletion of relation table dataProvider.Commit(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(InternalError(string.Format("Delete Expense {0:d} fails.", 0), "fail", ex)); } }