public ActionResult CreateUpdateOtherItemExpense(OtherExpenseModel otherItemExpenseModel) { if (!ModelState.IsValid) { return(ShowErrorMessage(GetModelErrors(ModelState))); } var otherItemExpense = new OtherExpense(); if (otherItemExpenseModel.Id > 0) { otherItemExpense = FarmManagementEntities.OtherExpenses.Single(x => x.Id == otherItemExpenseModel.Id); } otherItemExpense.FarmId = otherItemExpenseModel.FarmId; otherItemExpense.AccountId = otherItemExpenseModel.AccountId; otherItemExpense.OtherItemId = otherItemExpenseModel.OtherItemId; otherItemExpense.Amount = otherItemExpenseModel.Amount; otherItemExpense.Description = otherItemExpenseModel.Description; otherItemExpense.Date = otherItemExpenseModel.Date; if (otherItemExpenseModel.Id == 0) { otherItemExpense.UserId = otherItemExpenseModel.UserId; FarmManagementEntities.OtherExpenses.Add(otherItemExpense); } FarmManagementEntities.SaveChanges(); var message = string.Format(Constant.SuccessMessage, otherItemExpenseModel.Id > 0 ? "updated" : "added"); return(ShowSuccessMessage(message)); }
public ActionResult CreateUpdateOtherItemExpense(Int32 id) { var otherItemExpenseModel = new OtherExpenseModel(); if (id > 0) { var otherItemExpense = FarmManagementEntities.OtherExpenses.Single(x => x.Id == id); otherItemExpenseModel = otherItemExpense.ToType <OtherExpense, OtherExpenseModel>(); } return(PartialView("OtherItemExpensePartial", otherItemExpenseModel)); }