Ejemplo n.º 1
0
 public ActionResult Create(int brandId)
 {
     using (var context = new SiteContainer())
     {
         var brandGroup = context.BrandGroup.First(b => b.Id == brandId);
         ViewBag.BrandGroupName = brandGroup.Name;
         ViewBag.BrandId = brandId;
         int maxSortOrder = context.Brand.Max(c => (int?)c.SortOrder) ?? 0;
         var brand = new Brand
                         {
                             SortOrder = maxSortOrder + 1,
                             CurrentLang = CurrentLang.Id
                         };
         return View(brand);
         
     }
 }
Ejemplo n.º 2
0
        public ActionResult Create(Brand model, HttpPostedFileBase fileUpload, int brandId)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var brandGroup = context.BrandGroup.First(b => b.Id == brandId);

                    var cache = new Brand
                                    {
                                        Name = SiteHelper.UpdatePageWebName(model.Name), 
                                        Description = model.Description,
                                        SortOrder = model.SortOrder
                                    };


                    if (fileUpload != null)
                    {
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload, 500);
                        //fileUpload.SaveAs(filePath);
                        cache.ImageSource = fileName;

                        cache.BrandGroup = brandGroup;

                        context.AddToBrand(cache);

                        var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                        if (lang != null)
                        {
                            CreateOrChangeContentLang(context, model, cache, lang);
                        }
                    }
                    return RedirectToAction("BrandGroupDetails", "Home", new { area = "BrandCatalogue",id=brandGroup.Name });
                }
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Brand model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = context.Brand.Include("BrandGroup").FirstOrDefault(p => p.Id == model.Id);

                    if (cache != null)
                    {
                        if (fileUpload != null)
                        {
                            if (!string.IsNullOrEmpty(cache.ImageSource))
                            {
                                ImageHelper.DeleteImage(cache.ImageSource);
                            }

                            string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                            string filePath = Server.MapPath("~/Content/Images");
                            filePath = Path.Combine(filePath, fileName);
                            GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload, 500);
                            //fileUpload.SaveAs(filePath);
                            cache.ImageSource = fileName;
                        }
                        TryUpdateModel(cache, new[] { "Description", "SortOrder" });
                        cache.Name = SiteHelper.UpdatePageWebName(model.Name);

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

                    return RedirectToAction("BrandGroupDetails", "Home", new { area = "BrandCatalogue", id = cache.BrandGroup.Name });
                }

                
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 4
0
        private void CreateOrChangeContentLang(SiteContainer context, Brand instance, Brand cache, Language lang)
        {

            BrandLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.BrandLang.FirstOrDefault(p => p.BrandId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new BrandLang
                {
                    BrandId = instance.Id,
                    LanguageId = lang.Id,
                    Title = instance.Title,
                    Description = instance.Description
                };
                context.AddToBrandLang(newPostLang);
            }
            else
            {
                contenttLang.Title = instance.Title;
                contenttLang.Description = instance.Description;
            }
            context.SaveChanges();

        }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create a new Brand object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 /// <param name="brandGroupId">Initial value of the BrandGroupId property.</param>
 public static Brand CreateBrand(global::System.Int32 id, global::System.String name, global::System.Int32 sortOrder, global::System.Int32 brandGroupId)
 {
     Brand brand = new Brand();
     brand.Id = id;
     brand.Name = name;
     brand.SortOrder = sortOrder;
     brand.BrandGroupId = brandGroupId;
     return brand;
 }