Ejemplo n.º 1
0
 public ActionResult Create()
 {
     using (var context = new SiteContainer())
     {
         int maxSortOrder = context.Category.Max(c => (int?)c.SortOrder) ?? 0;
         var category = new Category
                            {
                                SortOrder = maxSortOrder + 1,
                                CurrentLang = CurrentLang.Id
                            };
         return View(category);
     }
 } 
Ejemplo n.º 2
0
        public ActionResult Edit(Category model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = context.Category.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[] { "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", "Category", new { area = "FactoryCatalogue" });
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Category model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = new Category
                    {
                        Name = SiteHelper.UpdatePageWebName(model.Name),
                        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);
                        cache.ImageSource = fileName;
                    }

                    context.AddToCategory(cache);

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

                    return RedirectToAction("Index", "Category", new { area = "FactoryCatalogue" });
                }
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 4
0
        private void CreateOrChangeContentLang(SiteContainer context, Category instance, Category cache, Language lang)
        {

            CategoryLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.CategoryLang.FirstOrDefault(p => p.CategoryId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new CategoryLang
                {
                    CategoryId = instance.Id,
                    LanguageId = lang.Id,
                    Title = instance.Title,
                };
                context.AddToCategoryLang(newPostLang);
            }
            else
            {
                contenttLang.Title = instance.Title;
            }
            context.SaveChanges();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategory(Category category)
 {
     base.AddObject("Category", category);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String name, global::System.String imageSource, global::System.Int32 sortOrder)
 {
     Category category = new Category();
     category.Id = id;
     category.Name = name;
     category.ImageSource = imageSource;
     category.SortOrder = sortOrder;
     return category;
 }