Example #1
0
 public ActionResult Create()
 {
     using (var context = new CatalogueContainer())
     {
         var category = new Category { SortOrder = 0 };
         var attributes = context.CategoryAttribute.ToList();
         ViewBag.Attributes = attributes;
         return View(category);
     }
 }
Example #2
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                using (var context = new CatalogueContainer())
                {
                    var category = new Category();


                    var attributes = context.CategoryAttribute.ToList();
                    PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr");
                    foreach (var kvp in postData)
                    {
                        var attribute = attributes.First(a => a.Id == kvp.Key);
                        if (kvp.Value)
                        {
                            if (!category.CategoryAttributes.Contains(attribute))
                                category.CategoryAttributes.Add(attribute);
                        }
                        else
                        {
                            if (category.CategoryAttributes.Contains(attribute))
                                category.CategoryAttributes.Remove(attribute);
                        }
                    }

                    TryUpdateModel(category, new[] { 
                    "Name", 
                    "Title", 
                    "SortOrder",
                    "SeoDescription",
                    "SeoKeywords",
                    "DescriptionTitle"
                    });
                    category.Description = HttpUtility.HtmlDecode(form["Description"]);
                    category.Name = category.Name.ToLower().Replace(" ", "");

                    context.AddToCategory(category);
                    context.SaveChanges();
                    return RedirectToAction("Index", "Category", new { area = "Admin" });
                }


            }
            catch
            {
                return View();
            }
        }
Example #3
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String title, global::System.String name, global::System.Int32 sortOrder)
 {
     Category category = new Category();
     category.Id = id;
     category.Title = title;
     category.Name = name;
     category.SortOrder = sortOrder;
     return category;
 }
Example #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategory(Category category)
 {
     base.AddObject("Category", category);
 }