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 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) { using (var context = new SiteContainer()) { var category = context.Category.First(c => c.Id == id); return View(category); } }
public ActionResult Edit(int id) { using (var context = new SiteContainer()) { var content = context.Content.First(c => c.Id == id); ViewBag.ContentName = content.Name; return View(content); } }
public ActionResult Index(string id) { using (var context = new SiteContainer()) { var model = new SiteViewModel(context, id ?? ""); this.SetSeoContent(model); ViewBag.isHomePage = model.IsHomePage; if (model.Content != null) ViewBag.ContentName = model.Content.Name; return View(model); } }
// // GET: /Brands/ public ActionResult Index(string category) { using (var context = new SiteContainer()) { var model = new CatalogueViewModel(context, category, null, (int)CategoryType.Brand); ViewBag.CategoryType = (int)CategoryType.Brand; this.SetSeoContent(model); ViewBag.CategoryId = model.Category.Id; ViewBag.CategoryName = model.Category.Name; return View(model); } }
public SiteViewModel(SiteContainer context, string contentName) { Title = "Poggenpohl"; if (contentName != null) { Content = contentName != "" ? context.Content.First(c => c.Name == contentName) : context.Content.First(c => c.MainPage); SeoDescription = Content.SeoDescription; SeoKeywords = Content.SeoKeywords; IsHomePage = Content.MainPage; } }
public ActionResult Index(string category, string subcategory) { using (var context = new SiteContainer()) { var model = new CatalogueViewModel(context, category, subcategory, (int)CategoryType.Category); ViewBag.CategoryType = (int)CategoryType.Category; this.SetSeoContent(model); if (model.Category != null) { ViewBag.CategoryId = model.Category.Id; } return View(model); } }
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 CatalogueViewModel(SiteContainer context, string categoryName, string subcategoryName, int categoryType) : base(context, null) { var categories = context.Category.Include("Children").Where(c => c.Parent == null && c.CategoryType == categoryType).ToList(); var subcategories = context.Category.Where(c => c.Name == categoryName && c.CategoryType == categoryType).SelectMany(c => c.Children).ToList(); _categories.AddRange(categories.Where(c => !c.MainPage).OrderBy(c => c.SortOrder).Select(c => new SelectListItem { Text = c.Title, Value = c.Name, Selected = c.Name == categoryName })); _subcategories.AddRange(subcategories.OrderBy(c => c.SortOrder).Select(c => new SelectListItem { Text = c.Title, Value = c.Name, Selected = c.Name == subcategoryName })); CategoriesSelectorData = new CategoriesSelectorData { Categories = _categories, SubCategories = _subcategories }; var category = categories.FirstOrDefault(c => c.Name == categoryName) ?? categories.First(c => c.MainPage); var subcategory = category.Children.FirstOrDefault(c => c.Name == subcategoryName); Title = category.Title; if (subcategory != null) Title += " > " + subcategory.Title; Category = subcategory ?? category; SeoDescription = Category.SeoDescription; SeoKeywords = Category.SeoKeywords; }
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 = "" }); } }