Exemplo n.º 1
0
        public ActionResult CreateTextBlock(BrandItem model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var brand = context.Brand.Include("BrandGroup").First(b => b.Id == model.BrandId);
                    var cache = new BrandItem
                    {
                        SortOrder = model.SortOrder,
                        ContentType = model.ContentType,
                        Brand = brand
                    };

                    model.Text = HttpUtility.HtmlDecode(model.Text);

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

                    return RedirectToAction("BrandDetails", "Home", new { area = "BrandCatalogue", brandGroup=brand.BrandGroup.Name, id = brand.Name });
                }
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 2
0
        public ActionResult EditTextBlock(BrandItem model)
        {
            using (var context = new SiteContainer())
            {
                var cache = context.BrandItem.Include("Brand").First(p => p.Id == model.Id);
                var brand = context.Brand.Include("BrandGroup").First(b => b.Id == model.BrandId);
                model.Text = HttpUtility.HtmlDecode(model.Text);
                //cache.Text = model.Text;

                TryUpdateModel(cache, new[] { "SortOrder" });

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


                return RedirectToAction("BrandDetails", "Home", new { area = "BrandCatalogue", brandGroup = brand.BrandGroup.Name, id = cache.Brand.Name });
            }
        }
Exemplo n.º 3
0
        private void CreateOrChangeContentLang(SiteContainer context, BrandItem instance, BrandItem cache, Language lang)
        {

            BrandItemLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.BrandItemLang.FirstOrDefault(p => p.BrandItemId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new BrandItemLang
                {
                    BrandItemId = instance.Id,
                    LanguageId = lang.Id,
                    Text = instance.Text
                };
                context.AddToBrandItemLang(newPostLang);
            }
            else
            {
                contenttLang.Text = instance.Text;
            }
            context.SaveChanges();

        }
Exemplo n.º 4
0
        public ActionResult EditImagesBlock(BrandItem model)
        {
            using (var context = new SiteContainer())
            {
                var brandItem = context.BrandItem.Include("Brand").First(b => b.Id == model.Id);
                var brand = context.Brand.Include("BrandGroup").First(b => b.Id == model.BrandId);
                TryUpdateModel(brandItem, new[] {"SortOrder"});

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file == null) continue;
                    if (string.IsNullOrEmpty(file.FileName)) continue;

                    var ci = new BrandItemImage();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);

                    ci.ImageSource = fileName;
                    brandItem.BrandItemImages.Add(ci);
                }

                context.SaveChanges();
                
                return RedirectToAction("BrandDetails", "Home", new { area = "BrandCatalogue", brandGroup = brand.BrandGroup.Name, id = brand.Name });
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BrandItem EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBrandItem(BrandItem brandItem)
 {
     base.AddObject("BrandItem", brandItem);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create a new BrandItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="contentType">Initial value of the ContentType property.</param>
 /// <param name="brandId">Initial value of the BrandId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static BrandItem CreateBrandItem(global::System.Int32 id, global::System.Int32 contentType, global::System.Int32 brandId, global::System.Int32 sortOrder)
 {
     BrandItem brandItem = new BrandItem();
     brandItem.Id = id;
     brandItem.ContentType = contentType;
     brandItem.BrandId = brandId;
     brandItem.SortOrder = sortOrder;
     return brandItem;
 }