public JsonResult Action(KBudgetActionModel model) { JsonResult json = new JsonResult(); var result = false; if (model.ID > 0) // we are trying to edit a record { var kBudgets = kbudgetServices.GetKBudgetsByID(model.ID); kBudgets.Name = model.Name; result = kbudgetServices.UpdateKBudgets(kBudgets); } else // we are trying to create a record { KBudget kBudgets = new KBudget(); kBudgets.Name = model.Name; result = kbudgetServices.SaveKBudgets(kBudgets); } if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to perform action on KBudgets" }; } return(json); }
public bool DeleteKBudgets(KBudget kBudget) { context.Entry(kBudget).State = System.Data.Entity.EntityState.Deleted; return(context.SaveChanges() > 0); }
public bool SaveKBudgets(KBudget kBudget) { context.KBudgets.Add(kBudget); return(context.SaveChanges() > 0); }