Example #1
0
 public ActionResult Create()
 {
     using (var context = new SiteContainer())
     {
         int maxSortOrder = context.BrandGroup.Max(c => (int?)c.SortOrder) ?? 0;
         var brand = new BrandGroup
         {
             SortOrder = maxSortOrder + 1,
             CurrentLang = CurrentLang.Id
         };
         return View(brand);
     }
 }
Example #2
0
        public ActionResult Edit(BrandGroup model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = context.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("Index", "Home", new { area = "BrandCatalogue" });
            }
            catch
            {
                return View();
            }
        }
Example #3
0
        public ActionResult Create(BrandGroup model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = new BrandGroup
                    {
                        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;
                    }

                    context.AddToBrandGroup(cache);

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

                    return RedirectToAction("Index", "Home", new { area = "BrandCatalogue" });
                }
            }
            catch
            {
                return View();
            }
        }
Example #4
0
        private void CreateOrChangeContentLang(SiteContainer context, BrandGroup instance, BrandGroup cache, Language lang)
        {

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

        }
Example #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BrandGroup EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBrandGroup(BrandGroup brandGroup)
 {
     base.AddObject("BrandGroup", brandGroup);
 }
Example #6
0
 /// <summary>
 /// Create a new BrandGroup 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="imageSource">Initial value of the ImageSource property.</param>
 public static BrandGroup CreateBrandGroup(global::System.Int32 id, global::System.String name, global::System.Int32 sortOrder, global::System.String imageSource)
 {
     BrandGroup brandGroup = new BrandGroup();
     brandGroup.Id = id;
     brandGroup.Name = name;
     brandGroup.SortOrder = sortOrder;
     brandGroup.ImageSource = imageSource;
     return brandGroup;
 }