public ActionResult Create(int? parentId, int categoryType, FormCollection form) { try { using (var context = new SiteContainer()) { var category = new Category { MainPage = false, CategoryType = categoryType }; Category parent = null; TryUpdateModel(category, new[] { "Name", "Title", "SortOrder", "SeoDescription", "SeoKeywords" }); category.Text = HttpUtility.HtmlDecode(form["Text"]); if (parentId.HasValue) { parent = context.Category.First(c => c.Id == parentId); parent.Children.Add(category); } else { context.AddToCategory(category); } context.SaveChanges(); string controllerName = GetControllerNameByCategoryType(categoryType); return parent != null ? RedirectToAction("Index", controllerName, new { area = "", category = parent.Name, subcategory = category.Name }) : RedirectToAction("Index", controllerName, new { area = "", category = category.Name }); } } catch { return View(); } }
public ActionResult Edit(int id, FormCollection form) { try { using (var context = new SiteContainer()) { var content = context.Content.First(c => c.Id == id); TryUpdateModel(content, new[] {"Title", "SeoDescription", "SeoKeywords" }); content.Text = HttpUtility.HtmlDecode(form["Text"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new {area = "", id = content.Name}); } } catch { return View(); } }
public ActionResult Edit(int id, FormCollection form) { try { using (var context = new SiteContainer()) { var category = context.Category.Include("Parent").First(c => c.Id == id); TryUpdateModel(category, new[] { "Name", "Title", "SortOrder", "SeoDescription", "SeoKeywords" }); category.Text = HttpUtility.HtmlDecode(form["Text"]); context.SaveChanges(); if (category.MainPage) return RedirectToAction("Index", "Catalogue", new { area = "" }); string controllerName = GetControllerNameByCategoryType(category.CategoryType); return category.Parent != null ? RedirectToAction("Index", controllerName, new { area = "", category = category.Parent.Name, subcategory = category.Name }) : RedirectToAction("Index", controllerName, new { area = "", category = category.Name }); } } catch { return View(); } }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var category = context.Category.Include("Children").First(c => c.Id == id); var categoryType = category.CategoryType; if (!category.Children.Any()) { context.DeleteObject(category); context.SaveChanges(); } string controllerName = GetControllerNameByCategoryType(categoryType); return RedirectToAction("Index", controllerName, new { area = "" }); } }