public ActionResult Create([Bind(Exclude = "IsActive")]Category category) { ModelState.Remove("IsActive"); if (ModelState.IsValid) { //save new record in database Category newRecord = new Category(); newRecord.CategoryId = Convert.ToInt32(db.Categories.Max(x => x.CategoryId)) + 1; newRecord.GroupID = category.GroupID; newRecord.CategoryName = category.CategoryName; newRecord.IsActive = true; newRecord.ModifieBy = WebSecurity.CurrentUserId; newRecord.CreatedBy = WebSecurity.CurrentUserId; newRecord.CreatedDate = System.DateTime.Now; newRecord.ModifiedDate = System.DateTime.Now; db.Categories.Add(newRecord); db.SaveChanges(); return RedirectToAction("Index", "AddCategory"); } return View(category); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { var userToUpdate = db.Categories.SingleOrDefault(u => u.CategoryId == category.CategoryId); if (userToUpdate != null) { userToUpdate.CategoryName = category.CategoryName; userToUpdate.GroupID = category.GroupID; userToUpdate.IsActive = category.IsActive; userToUpdate.ModifieBy = WebSecurity.CurrentUserId; userToUpdate.ModifiedDate = System.DateTime.Now; db.SaveChanges(); } return RedirectToAction("Index"); } return View(category); }