// // GET: /Admin/Category/ private void LoadChildren(Category category, int level) { category.Children.Load(); foreach (var child in category.Children) { level++; child.Level = level; LoadChildren(child, level); level--; } }
public ActionResult Create(Category category) { if (this.ModelState.IsValid) { var cat = new Category { Name = category.Name }; _db.Categories.Add(cat); _db.SaveChanges(); return RedirectToAction("Index"); } return View(); }
public ActionResult Create() { using (var context = new ShopContainer()) { int maxSortOrder = context.Category.Max(c => (int?)c.SortOrder) ?? 0; var category = new Category { SortOrder = maxSortOrder + 1, }; return View(category); } }
public ActionResult Edit(Category category) { if (this.ModelState.IsValid) { var cat = _db.Categories.FirstOrDefault(x => x.Id == category.Id); if (cat != null) { cat.Name = category.Name; _db.SaveChanges(); return RedirectToAction("Index"); } } return View(); }
public ActionResult Edit(int id, Category model) { try { using (var context = new ShopContainer()) { var category = context.Category.First(c => c.Id == id); TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder", "Title" }); context.SaveChanges(); return RedirectToAction("Category", "Home", new { area = "", id = category.Name }); } } catch { return View(); } }
public ActionResult Create(Category model) { try { using (var context = new ShopContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder", "Title" }); context.AddToCategory(category); context.SaveChanges(); return RedirectToAction("Category", "Home", new { area = "", id = category.Name }); } } catch { return View(); } }
public ActionResult Create(int? parentId, FormCollection form, HttpPostedFileBase uploadFile) { try { using (var context = new ShopContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder","Title" }); if (uploadFile != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); uploadFile.SaveAs(filePath); category.ImageSource = fileName; } if (parentId.HasValue) { var parent = context.Category.First(c => c.Id == parentId); parent.Children.Add(category); } else { context.AddToCategory(category); } context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
/// <summary> /// Create a new Category object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="title">Initial value of the Title property.</param> public static Category CreateCategory(global::System.Int32 id, global::System.String name, global::System.String title) { Category category = new Category(); category.Id = id; category.Name = name; category.Title = title; return category; }
/// <summary> /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCategory(Category category) { base.AddObject("Category", category); }