public ActionResult Edit(CategoryBrandItem model)
        {
            try
            {
                
                using (var context = new SiteContainer())
                {

                    var brandItem = context.CategoryBrandItem.Include("CategoryBrand").First(b => b.Id == model.Id);
                    var categoryBrand = context.CategoryBrand.Include("Category").First(c => c.Id == brandItem.CategoryBrandId);


                    TryUpdateModel(brandItem, new[] { "Content", "SortOrder" });
                    brandItem.Content = HttpUtility.HtmlDecode(brandItem.Content);

                    var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                    if (lang != null)
                    {
                        CreateOrChangeContentLang(context, model, brandItem, lang);
                    }

                    return RedirectToAction("Details", "Brand",
                                             new
                                             {
                                                 area = "FactoryCatalogue",
                                                 categoryId = categoryBrand.Category.Name,
                                                 id = brandItem.CategoryBrand.Name
                                             });
                }
            }
            catch
            {
                return View();
            }
        }
 public ActionResult Create(int brandId)
 {
     using (var context = new SiteContainer())
     {
         var brand = context.CategoryBrand.Include("Category").First(b => b.Id == brandId);
         int maxSortOrder = context.CategoryBrandItem.Where(c => c.CategoryBrandId == brandId).Max(c => (int?)c.SortOrder) ?? 0;
         var brandItem = new CategoryBrandItem
                             {
                                 CategoryBrand = brand,
                                 SortOrder = maxSortOrder + 1,
                                 CurrentLang = CurrentLang.Id
                             };
         ViewBag.BrandName = brand.Name;
         ViewBag.CategoryName = brand.Category.Name;
         return View(brandItem);
     }
 } 
        public ActionResult Create(CategoryBrandItem model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var brand = context.CategoryBrand.Include("Category").First(b => b.Id == model.CategoryBrandId);

                    var cache = new CategoryBrandItem
                    {
                        CategoryBrand = brand,
                        Content = HttpUtility.HtmlDecode(model.Content),
                        SortOrder = model.SortOrder
                    };

                    context.AddToCategoryBrandItem(cache);

                    var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                    if (lang != null)
                    {
                        CreateOrChangeContentLang(context, model, cache, lang);
                    }

                    return RedirectToAction("Details", "Brand",
                                            new
                                                {
                                                    area = "FactoryCatalogue",
                                                    categoryId = brand.Category.Name,
                                                    id = brand.Name
                                                });
                }
            }
            catch
            {
                return View();
            }
        }
Exemple #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the CategoryBrandItem EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategoryBrandItem(CategoryBrandItem categoryBrandItem)
 {
     base.AddObject("CategoryBrandItem", categoryBrandItem);
 }
Exemple #5
0
 /// <summary>
 /// Create a new CategoryBrandItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="categoryBrandId">Initial value of the CategoryBrandId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static CategoryBrandItem CreateCategoryBrandItem(global::System.Int32 id, global::System.Int32 categoryBrandId, global::System.Int32 sortOrder)
 {
     CategoryBrandItem categoryBrandItem = new CategoryBrandItem();
     categoryBrandItem.Id = id;
     categoryBrandItem.CategoryBrandId = categoryBrandId;
     categoryBrandItem.SortOrder = sortOrder;
     return categoryBrandItem;
 }
        private void CreateOrChangeContentLang(SiteContainer context, CategoryBrandItem instance, CategoryBrandItem cache, Language lang)
        {

            CategoryBrandItemLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.CategoryBrandItemLang.FirstOrDefault(p => p.CategoryBrandItemId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new CategoryBrandItemLang
                {
                    CategoryBrandItemId = instance.Id,
                    LanguageId = lang.Id,
                    Title = instance.Title,
                    Text = HttpUtility.HtmlDecode(instance.Text)
                };
                context.AddToCategoryBrandItemLang(newPostLang);
            }
            else
            {
                contenttLang.Title = instance.Title;
                contenttLang.Text = HttpUtility.HtmlDecode(instance.Text);
            }
            context.SaveChanges();

        }