예제 #1
0
        public ActionResult Create(CategoryBrand model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = context.Category.First(c => c.Id == model.CategoryId);
                    var cache = new CategoryBrand
                                    {
                                        Category = category,
                                        SortOrder = model.SortOrder,
                                        Name = SiteHelper.UpdatePageWebName(model.Name),
                                        Title = model.Title
                                    };
                    context.AddToCategoryBrand(cache);
                    context.SaveChanges();

                    return RedirectToAction("Details", "Category", new { area = "FactoryCatalogue", id = category.Name });
                }
            }
            catch
            {
                return View();
            }
        }
예제 #2
0
 private void CreateOrChangeContentLang(SiteContainer context, Content instance, Content cache, Language lang)
 {
    
         ContentLang contenttLang = null;
         if (cache != null)
         {
             contenttLang = context.ContentLang.FirstOrDefault(p => p.ContentId == cache.Id && p.LanguageId == lang.Id);
         }
         if (contenttLang == null)
         {
             var newPostLang = new ContentLang
                                   {
                                       ContentId = instance.Id,
                                       LanguageId = lang.Id,
                                       Title = instance.Title,
                                       Text = HttpUtility.HtmlDecode(instance.Text),
                                       SeoDescription = instance.SeoDescription,
                                       SeoKeywords = instance.SeoKeywords
                                   };
             context.AddToContentLang(newPostLang);
         }
         else
         {
             contenttLang.Title = instance.Title;
             contenttLang.Text = HttpUtility.HtmlDecode(instance.Text);
             contenttLang.SeoDescription = instance.SeoDescription;
             contenttLang.SeoKeywords = instance.SeoKeywords;
         }
         context.SaveChanges();
    
 }
예제 #3
0
 public ActionResult Edit(CategoryBrand model)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var brand = context.CategoryBrand.Include("Category").First(b => b.Id == model.Id);
             TryUpdateModel(brand, new[] { "SortOrder", "Title" });
             brand.Name = SiteHelper.UpdatePageWebName(model.Name);
             context.SaveChanges();
             return RedirectToAction("Details", "Category", new { area = "FactoryCatalogue", id = brand.Category.Name });
         }
     }
     catch
     {
         return View();
     }
 }
예제 #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();

        }
예제 #5
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var brand = context.Brand.Include("BrandGroup").Include("BrandLangs").First(b => b.Id == id);
                var bgn = brand.BrandGroup.Name;
                ImageHelper.DeleteImage(brand.ImageSource);

                while (brand.BrandLangs.Any())
                {
                    var bl = brand.BrandLangs.First();
                    context.DeleteObject(bl);
                }
                context.DeleteObject(brand);
                context.SaveChanges();

                return RedirectToAction("BrandGroupDetails", "Home", new {area = "BrandCatalogue", id = bgn});
            }
        }
예제 #6
0
 public ActionResult DeleteTextBlock(int id)
 {
     using (var context = new SiteContainer())
     {
         var articleItem = context.ArticleItem.Include("Article").Include("ArticleItemLangs").First(b => b.Id == id);
         while (articleItem.ArticleItemLangs.Any())
         {
             var ail = articleItem.ArticleItemLangs.First();
             context.DeleteObject(ail);
         }
         context.DeleteObject(articleItem);
         context.SaveChanges();
         return RedirectToAction("Articles", "Home", new { area = "" });
     }
 }
예제 #7
0
        private void CreateOrChangeContentLang(SiteContainer context, ArticleItem instance, ArticleItem cache, Language lang)
        {

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

        }
예제 #8
0
        public ActionResult DeleteImageBlock(int id)
        {
            using (var context = new SiteContainer())
            {
                var articleItem = context.ArticleItem.Include("Article").First(b => b.Id == id);

                ImageHelper.DeleteImage(articleItem.ImageSource);

                context.DeleteObject(articleItem);
                context.SaveChanges();
                return RedirectToAction("Articles", "Home", new { area = "" });
            }
        }
예제 #9
0
        public ActionResult CreateImageBlock(ArticleItem model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var article = context.Article.Include("ArticleItems").First(b => b.Id == model.ArticleId);

                    int maxSortOrder = article.ArticleItems.Max(c => (int?)c.SortOrder) ?? 0;


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

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

                        var ai = new ArticleItem {SortOrder = maxSortOrder, ContentType = 2};
                        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);
                        
                        ai.ImageSource = fileName;

                        article.ArticleItems.Add(ai);
                    }

                    context.SaveChanges();


                    return RedirectToAction("Articles", "Home", new { area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
예제 #10
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 });
            }
        }
예제 #11
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var article = context.Article.Include("ArticleItems").Include("ArticleLangs").First(a => a.Id == id);
                while (article.ArticleLangs.Any())
                {
                    var al = article.ArticleLangs.First();
                    context.DeleteObject(al);
                }


                while (article.ArticleItems.Any())
                {
                    var item = article.ArticleItems.First();
                    var articleItem = context.ArticleItem.Include("ArticleItemLangs").First(ai => ai.Id == item.Id);

                    while (articleItem.ArticleItemLangs.Any())
                    {
                        var ail = articleItem.ArticleItemLangs.First();
                        context.DeleteObject(ail);
                    }

                    ImageHelper.DeleteImage(item.ImageSource);

                    context.DeleteObject(articleItem);
                }


                context.DeleteObject(article);
                context.SaveChanges();

                return RedirectToAction("Articles", "Home", new { area = "" });
            }
        }
예제 #12
0
        public ActionResult DeleteTextBlock(int id)
        {
            using (var context = new SiteContainer())
            {
                var brandItem = context.BrandGroupItem.Include("BrandGroup").Include("BrandGroupItemLangs").First(b => b.Id == id);
                var brand = context.BrandGroup.First(b => b.Id == brandItem.BrandGroupId);

                while (brandItem.BrandGroupItemLangs.Any())
                {
                    var bal = brandItem.BrandGroupItemLangs.First();
                    context.DeleteObject(bal);
                }
                context.DeleteObject(brandItem);
                context.SaveChanges();
                return RedirectToAction("BrandGroupDetails", "Home", new { area = "BrandCatalogue", id = brand.Name });
            }
        }
예제 #13
0
        private void CreateOrChangeContentLang(SiteContainer context, BrandGroupItem instance, BrandGroupItem cache, Language lang)
        {

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

        }
예제 #14
0
        public ActionResult DeleteImagesBlock(int id)
        {
            using (var context = new SiteContainer())
            {
                var brandItem = context.BrandItem.Include("Brand").Include("BrandItemImages").First(b => b.Id ==id);
                var brand = context.Brand.Include("BrandGroup").First(b => b.Id == brandItem.BrandId);

                while (brandItem.BrandItemImages.Any())
                {
                    var image = brandItem.BrandItemImages.First();
                    ImageHelper.DeleteImage(image.ImageSource);
                    context.DeleteObject(image);
                }

                context.DeleteObject(brandItem);
                context.SaveChanges();

                return RedirectToAction("BrandDetails", "Home", new { area = "BrandCatalogue", brandGroup = brand.BrandGroup.Name, id = brand.Name });
            }
        }
예제 #15
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var category = context.Category.Include("CategoryLangs").First(b => b.Id == id);
                ImageHelper.DeleteImage(category.ImageSource);

                while (category.CategoryLangs.Any())
                {
                    var cl = category.CategoryLangs.First();
                    context.DeleteObject(cl);
                }

                context.DeleteObject(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Category", new {area = "FactoryCatalogue"});
            }
        }
예제 #16
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var brand = context.CategoryBrand.Include("Category").Include("CategoryBrandItems").First(b => b.Id == id);
                var categoryName = brand.Category.Name;

                foreach (var categoryBrandItem in brand.CategoryBrandItems)
                {
                    categoryBrandItem.CategoryBrandItemLangs.Load();
                }

                while (brand.CategoryBrandItems.Any())
                {
                    var cbi = brand.CategoryBrandItems.First();
                    while (cbi.CategoryBrandItemLangs.Any())
                    {
                        var cbil = cbi.CategoryBrandItemLangs.First();
                        context.DeleteObject(cbil);
                    }
                    context.DeleteObject(cbi);
                }

                context.DeleteObject(brand);
                context.SaveChanges();
                return RedirectToAction("Details", "Category", new { area = "FactoryCatalogue", id = categoryName });
            }
        }
예제 #17
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();
        }
예제 #18
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var brandItem = context.CategoryBrandItem.Include("CategoryBrandItemLangs").Include("CategoryBrand").First(b => b.Id == id);
                var categoryBrand = context.CategoryBrand.Include("Category").First(c => c.Id == brandItem.CategoryBrandId);

                while (brandItem.CategoryBrandItemLangs.Any())
                {
                    var bl = brandItem.CategoryBrandItemLangs.First();
                    context.DeleteObject(bl);
                }

                context.DeleteObject(brandItem);
                context.SaveChanges();
                return RedirectToAction("Details", "Brand", new { area = "FactoryCatalogue", categoryId = categoryBrand.Category.Name, id = categoryBrand.Name });
            }
        }