public ActionResult Create(int? parentId, FormCollection collection) { using (var context = new SiteContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "Title", "Description", "BottomDescription", "BottomDescriptionTitle", "ShowOnMainPage", "PageTitle" }); if (parentId.HasValue) { var parent = context.Category.First(c => c.Id == parentId); parent.Children.Add(category); } else { context.AddToCategory(category); } context.SaveChanges(); return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name }); } }
public ActionResult Create(FormCollection collection) { using (var context = new SiteContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "Title", "Description", "BottomDescription", "BottomDescriptionTitle" }); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name }); } }