public ActionResult DeleteManager(int?id) { if (id == null) { return(RedirectToAction("Index")); } var managerToDelete = new KeyManagerModel() { Id = id.GetValueOrDefault() }; db.KeysManagers.Attach(managerToDelete); db.KeysManagers.Remove(managerToDelete); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddOrUpdate(KeyManagerAddOrUpdateViewModel m) { if (m.Id == null) { var newManager = new KeyManagerModel() { FactoryName = m.FactoryName, AuctionID = m.AuctionID, Keys = m.Keys }; db.KeysManagers.Add(newManager); db.SaveChanges(); } else { var editManager = db.KeysManagers.Find(m.Id); editManager.Keys = m.Keys; editManager.FactoryName = m.FactoryName; editManager.AuctionID = m.AuctionID; db.SaveChanges(); } return(RedirectToAction("Index")); }