public async Task <ActionResult> Edit(FeeCategoryVm feeCategory) { if (string.IsNullOrWhiteSpace(feeCategory.CategoryName) || string.IsNullOrEmpty(feeCategory.CategoryName)) { ModelState.AddModelError("Error", "You cannot have blank categories in the application!"); return(View(feeCategory)); } if (ModelState.IsValid) { var model = await Db.FeeCategories.FindAsync(feeCategory.Id); Db.Entry(model).State = EntityState.Modified; await Db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(feeCategory)); }
public async Task <ActionResult> Create(FeeCategoryVm feeCategory) { if (Db.FeeCategories.Any(fc => fc.CategoryName.Equals(feeCategory.CategoryName))) { ModelState.AddModelError("Error", "A Fee Category already exists with the name you have supplied or your or the name is blank! Please fill a valid name for the category!"); return(View(feeCategory)); } if (ModelState.IsValid) { var model = new FeeCategory { CategoryName = feeCategory.CategoryName, CategoryDescription = feeCategory.CategoryDescription }; Db.FeeCategories.Add(model); await Db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(feeCategory)); }