public ActionResult Create(MenuSiteModel Model) { if (String.IsNullOrEmpty(Model.Name)) { return(Create().WithError("Please provide a valid name!")); } MenuSite newEntry = new MenuSite(); newEntry.MenuName = Model.Name; using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var MenuSiteModelId = dc.MenuSites.FirstOrDefault(i => i.MenuName == Model.SelectedParent); if (MenuSiteModelId != null) { newEntry.ParentId = MenuSiteModelId.MenuId; } else { newEntry.ParentId = 0; } dc.MenuSites.Add(newEntry); dc.SaveChanges(); } return(RedirectToAction <HomeController>(c => c.Index()).WithSuccess("Item Created!")); }
public ActionResult Delete(string myList) { using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var MenuSiteEntry = dc.MenuSites.FirstOrDefault(i => i.MenuName == myList); if (MenuSiteEntry != null) { DeleteBranch(dc, MenuSiteEntry); dc.SaveChanges(); } else { return(RedirectToAction <HomeController>(c => c.Index()) .WithError("Please select a valid item to delete!")); } } return(RedirectToAction <HomeController>(c => c.Index()) .WithSuccess("Branch Item successfully deleted.")); }