Ejemplo n.º 1
0
        public ActionResult Create(int id, FormCollection form, string filter)
        {
            try
            {
                using (var context = new CatalogueContainer())
                {
                    var category = context.Category.First(c => c.Id == id);
                    var brand = new Brand { Category = category };
                    PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr");
                    foreach (var kvp in cbData)
                    {
                        var attrId = kvp.Key;
                        bool attrValue = kvp.Value;
                        if (attrValue)
                        {
                            var attribute = context.CategoryAttribute.First(c => c.Id == attrId);
                            brand.CategoryAttributes.Add(attribute);
                        }
                    }

                    TryUpdateModel(brand, new[] { "Title", "Name", "SortOrder", "Href", "DescriptionTitle" });
                    brand.Name = brand.Name.ToLower().Replace(" ", "");
                    brand.Description = HttpUtility.HtmlDecode(form["Description"]);
                    context.AddToBrand(brand);
                    context.SaveChanges();

                    return RedirectToAction("Index", "Catalogue", new { area = "", category = category.Name, filter=filter });
                }
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new Brand 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="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static Brand CreateBrand(global::System.Int32 id, global::System.String title, global::System.String name, global::System.Int32 categoryId, global::System.Int32 sortOrder)
 {
     Brand brand = new Brand();
     brand.Id = id;
     brand.Title = title;
     brand.Name = name;
     brand.CategoryId = categoryId;
     brand.SortOrder = sortOrder;
     return brand;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Brand EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBrand(Brand brand)
 {
     base.AddObject("Brand", brand);
 }