public ActionResult AddOrEdit(User userModel) { using (DbModels1 dbModel1 = new DbModels1()) { dbModel1.Users.Add(userModel); dbModel1.SaveChanges(); } ModelState.Clear(); return(View("AddOrEdit", new User())); }
public ActionResult Edit(int id, Customer customer) { try { // TODO: Add update logic here using (DbModels1 dbModel = new DbModels1()) { dbModel.Entry(customer).State = System.Data.EntityState.Modified; dbModel.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Customer customer) { try { // TODO: Add insert logic here using (DbModels1 dbModel = new DbModels1()) { dbModel.Customer.Add(customer); dbModel.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here using (DbModels1 dbModel = new DbModels1()) { Customer customer = dbModel.Customer.Where(x => x.Id == id).FirstOrDefault(); dbModel.Customer.Remove(customer); dbModel.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }