示例#1
0
        public ActionResult Add(FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = new Category();

                if (!string.IsNullOrEmpty(form["parentId"]))
                {
                    int parentId = Convert.ToInt32(form["parentId"]);
                    var parent = context.Category.First(c => c.Id == parentId);
                    category.Parent = parent;
                }


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


                TryUpdateModel(category, new[] { "Name", "Title", "TitleEng", "SortOrder" });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);
                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue",
                                        new
                                            {
                                                Area = "",
                                                category = category.Parent != null ? category.Parent.Name : category.Name,
                                                subCategory = category.Parent != null ? category.Name : null
                                            });
            }
        }
示例#2
0
        //
        // GET: /Admin/Category/

        public ActionResult Add(int? id)
        {
            using (var context = new StructureContainer())
            {
                var category = new Category { SortOrder = 0 };
                var attributes = context.ProductAttribute.ToList();
                ViewBag.Attributes = attributes;

                ViewData["parentId"] = id;
                if (id.HasValue)
                {
                    var parent = context.Category.First(c => c.Id == id);
                    category.Parent = parent;
                }

                return View(category);
            }
        }
示例#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="titleEng">Initial value of the TitleEng property.</param>
 /// <param name="textEng">Initial value of the TextEng property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String title, global::System.String name, global::System.String titleEng, global::System.String textEng)
 {
     Category category = new Category();
     category.Id = id;
     category.Title = title;
     category.Name = name;
     category.TitleEng = titleEng;
     category.TextEng = textEng;
     return category;
 }
示例#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);
 }
示例#5
0
        public ActionResult Edit(Category model, FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = context.Category.Include("Parent").First(c => c.Id == model.Id);

                TryUpdateModel(category, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "TitleEng",
                                                "SortOrder"
                                            });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);

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

                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent != null ? category.Parent.Name : category.Name });
            }
        }