public ActionResult Create(CategoryBrand model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = context.Category.First(c => c.Id == model.CategoryId);
                    var cache = new CategoryBrand
                                    {
                                        Category = category,
                                        SortOrder = model.SortOrder,
                                        Name = SiteHelper.UpdatePageWebName(model.Name),
                                        Title = model.Title
                                    };
                    context.AddToCategoryBrand(cache);
                    context.SaveChanges();

                    return RedirectToAction("Details", "Category", new { area = "FactoryCatalogue", id = category.Name });
                }
            }
            catch
            {
                return View();
            }
        }
        public FactoryCatalogueModel(Language lang, SiteContainer context, string categoryId, string brandId)
            : base(lang, context, "factory")
        {
            Categories = context.Category.ToList();
            foreach (var category in Categories)
            {
                category.CurrentLang = lang.Id;
            }


            if (!string.IsNullOrEmpty(categoryId))
            {
                Category = context.Category.Include("CategoryBrands").First(c => c.Name == categoryId);
                Category.CurrentLang = lang.Id;

                if (!string.IsNullOrEmpty(brandId))
                {
                    Brand = Category.CategoryBrands.First(c => c.Name == brandId);
                    Brand.CategoryBrandItems.Load();
                    foreach (var item in Brand.CategoryBrandItems)
                    {
                        item.CurrentLang = lang.Id;
                    }
                }

            }




        }
 public ActionResult Create(int category)
 {
     using (var context = new SiteContainer())
     {
         var cat = context.Category.First(c => c.Id == category);
         int maxSortOrder = context.CategoryBrand.Where(c => c.CategoryId == cat.Id).Max(c => (int?)c.SortOrder) ?? 0;
         var categoryBrand = new CategoryBrand
         {
             SortOrder = maxSortOrder + 1,
             Category = cat
         };
         ViewBag.CategoryName = cat.Name;
         return View(categoryBrand);
     }
 }
 public ActionResult Edit(CategoryBrand model)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var brand = context.CategoryBrand.Include("Category").First(b => b.Id == model.Id);
             TryUpdateModel(brand, new[] { "SortOrder", "Title" });
             brand.Name = SiteHelper.UpdatePageWebName(model.Name);
             context.SaveChanges();
             return RedirectToAction("Details", "Category", new { area = "FactoryCatalogue", id = brand.Category.Name });
         }
     }
     catch
     {
         return View();
     }
 }
Exemple #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the CategoryBrand EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategoryBrand(CategoryBrand categoryBrand)
 {
     base.AddObject("CategoryBrand", categoryBrand);
 }
Exemple #6
0
 /// <summary>
 /// Create a new CategoryBrand object.
 /// </summary>
 /// <param name="id">Initial value of the Id 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>
 /// <param name="title">Initial value of the Title property.</param>
 public static CategoryBrand CreateCategoryBrand(global::System.Int32 id, global::System.String name, global::System.Int32 categoryId, global::System.Int32 sortOrder, global::System.String title)
 {
     CategoryBrand categoryBrand = new CategoryBrand();
     categoryBrand.Id = id;
     categoryBrand.Name = name;
     categoryBrand.CategoryId = categoryId;
     categoryBrand.SortOrder = sortOrder;
     categoryBrand.Title = title;
     return categoryBrand;
 }