Ejemplo n.º 1
0
        public ActionResult Add(FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var content = new Content { MainPage = false, IsGallery = false };

                TryUpdateModel(content, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "TitleEng",
                                                "PageTitle",
                                                "PageTitleEng",
                                                "SortOrder",
                                                "SeoDescription",
                                                "SeoKeywords"
                                            });
                content.Text = HttpUtility.HtmlDecode(form["Text"]);
                content.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);

                context.AddToContent(content);

                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { id = content.Name, area = "" });
            }
        }
Ejemplo n.º 2
0
        //
        // GET: /Catalogue/

        public ActionResult Index(string category, string subCategory, int? filter)
        {
            using (var context = new StructureContainer())
            {
                var model = new CatalogueViewModel(context, category, subCategory, filter);

                if (model.SubCategory == null && model.Category.Products.Count == 0 && model.Category.Children.Count > 0)
                {
                    var child = model.Category.Children.First();
                    return RedirectToAction("Index", new { category = model.Category.Name, subCategory = child.Name });
                }


                this.SetSeoContent(model);
                ViewBag.MainMenu = model.MainMenu;
                ViewBag.CategoryName = model.Category.Name;
                if (model.SubCategory != null)
                    ViewBag.SubCategoryName = model.SubCategory.Name;
                ViewBag.CategoryName = model.Category.Name;
                ViewBag.Filter = model.CurrentFilterId;
                if (model.Content != null)
                    ViewBag.ContentName = model.Content.Name;
                return View(model);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Content model, FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var content = context.Content.First(c => c.Id == model.Id);

                TryUpdateModel(content, new[]
                                            {
                                               "Name",
                                                "Title",
                                                "TitleEng",
                                                "PageTitle",
                                                "PageTitleEng",
                                                "SortOrder",
                                                "SeoDescription",
                                                "SeoKeywords"
                                            });
                content.Text = HttpUtility.HtmlDecode(form["Text"]);
                content.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);

                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { id = content.Name, area = "" });
            }
        }
Ejemplo n.º 4
0
        //
        // GET: /Admin/ProductAttributes/

        public ActionResult Index()
        {
            using (var context = new StructureContainer())
            {
                var attributes = context.ProductAttribute.ToList();
                return View(attributes);
            }
        }
Ejemplo n.º 5
0
 public ActionResult Categories()
 {
     using (var context = new StructureContainer())
     {
         var categories = context.Category.Where(c => c.CategoryId == null).ToList();
         return PartialView("Categories", categories);
     }
 }
Ejemplo n.º 6
0
 public ActionResult Edit(int id)
 {
     using (var context = new StructureContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         return View(content);
     }
 }
Ejemplo n.º 7
0
 public ActionResult Edit(int id)
 {
     using (var context = new StructureContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == id);
         return View(productAttribute);
     }
 }
Ejemplo n.º 8
0
        public CatalogueViewModel(StructureContainer context, string categoryName, string subCategoryName, int? filter = null)
            : base(context, null)
        {
            var title = "";
            var category = Context.Category
                .Include("Children")
                //.Include("ProductAttributes")
                .First(c => c.Name == categoryName);
            category.ProductAttributes.Load();
            Category = category;

            var currentCategory = category;
            CurrentCategory = category;
            title += (SiteSettings.Language==Language.Ru? category.Title:category.TitleEng);

            if (!string.IsNullOrEmpty(subCategoryName))
            {
                var subCategory = category.Children.First(c => c.Name == subCategoryName);
                subCategory.ProductAttributes.Load();
                SubCategory = subCategory;
                currentCategory = subCategory;
                CurrentCategory = subCategory;
                title += (SiteSettings.Language==Language.Ru? subCategory.Title:subCategory.TitleEng);
            }

            SubcategoriesMenu = new Menu();
            foreach (var c in category.Children)
            {
                SubcategoriesMenu.Add(
                    new MenuItem
                    {
                        ContentId = c.Id,
                        ContentName = c.Name,
                        IsMainPage = false,
                        Selected = c.Name == subCategoryName,
                        SortOrder = c.SortOrder,
                        Title = SiteSettings.Language==Language.Ru? c.Title:c.TitleEng
                    });
            }

            foreach (var m in MainMenu.Where(m => m.IsGalleryMenuItem))
            {
                m.Selected = true;
            }

            CurrentFilterId = filter;


            //var productAttributes = Context.ProductAttribute.Where(p => !filter.HasValue || p.Id == filter);

            var products = Context.Product.Include("ProductAttributes").Where(p => p.CategoryId == currentCategory.Id).ToList();
            Products = ApplyFilter(products, filter);


            Title += " - " + title;
            SeoDescription = currentCategory.SeoDescription;
            SeoKeywords = currentCategory.SeoKeywords;
        }
Ejemplo n.º 9
0
 public ActionResult NotFound()
 {
     using (var context = new StructureContainer())
     {
         SiteViewModel model = new SiteViewModel(context, null);
         ViewBag.MainMenu = model.MainMenu;
         return View(model);
     }
 }
Ejemplo n.º 10
0
 public ActionResult Edit(ProductAttribute model, FormCollection form)
 {
     using (var context = new StructureContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == model.Id);
         TryUpdateModel(productAttribute, new[] { "Title", "TitleEng" });
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Ejemplo n.º 11
0
 public ActionResult Create(ProductAttribute model)
 {
     using (var context = new StructureContainer())
     {
         var pa = new ProductAttribute();
         TryUpdateModel(pa, new[] { "Title", "TitleEng" });
         context.AddToProductAttribute(pa);
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 12
0
        public ActionResult Index(string id)
        {
            using (var context = new StructureContainer())
            {
                var model = new SiteViewModel(context, id ?? "");

                this.SetSeoContent(model);
                ViewBag.MainMenu = model.MainMenu;
                ViewBag.isHomePage = model.IsHomePage;
                if (model.Content != null)
                    ViewBag.ContentName = model.Content.Name;
                return View(model);
            }
        }
Ejemplo n.º 13
0
        public ActionResult Create(FormCollection form, int categoryId, HttpPostedFileBase fileUpload)
        {
            using (var context = new StructureContainer())
            {
                Product product = new Product();
                Category category = context.Category.Include("Parent").First(c => c.Id == categoryId);
                product.Category = category;

                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Remove(attribute);
                    }
                }


                TryUpdateModel(product, new[] { "Title", "TitleEng", "Description", "DescriptionEng", "ShowOnMainPage","Discount","DiscountText" });

                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);

                    product.ImageSource = fileName;
                }

                context.AddToProduct(product);

                context.SaveChanges();

                return category.Parent != null
                    ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name })
                    : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name });
            }
        }
Ejemplo n.º 14
0
        public ActionResult Add(FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = new Category();

                if (!string.IsNullOrEmpty(form["parentId"]))
                {
                    int parentId = Convert.ToInt32(form["parentId"]);
                    var parent = context.Category.First(c => c.Id == parentId);
                    category.Parent = parent;
                }


                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }


                TryUpdateModel(category, new[] { "Name", "Title", "TitleEng", "SortOrder" });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);
                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue",
                                        new
                                            {
                                                Area = "",
                                                category = category.Parent != null ? category.Parent.Name : category.Name,
                                                subCategory = category.Parent != null ? category.Name : null
                                            });
            }
        }
Ejemplo n.º 15
0
        public ActionResult Delete(int id)
        {
            using (var context = new StructureContainer())
            {
                var productAttribute = context.ProductAttribute
                    .Include("Categories")
                    .Include("Products")
                    .First(pa => pa.Id == id);

                productAttribute.Products.Clear();
                productAttribute.Categories.Clear();

                context.DeleteObject(productAttribute);
                context.SaveChanges();
            }
            return RedirectToAction("Index");
        }
Ejemplo n.º 16
0
        //
        // GET: /Admin/Category/

        public ActionResult Add(int? id)
        {
            using (var context = new StructureContainer())
            {
                var category = new Category { SortOrder = 0 };
                var attributes = context.ProductAttribute.ToList();
                ViewBag.Attributes = attributes;

                ViewData["parentId"] = id;
                if (id.HasValue)
                {
                    var parent = context.Category.First(c => c.Id == id);
                    category.Parent = parent;
                }

                return View(category);
            }
        }
Ejemplo n.º 17
0
 public ActionResult Create(int id)
 {
     using (var context = new StructureContainer())
     {
         var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == id);
         ViewBag.CategoryId = category.Id;
         ViewBag.Attributes = category.ProductAttributes;
         if (category.Parent != null)
         {
             ViewBag.CategoryName = category.Parent.Name;
             ViewBag.SubCategoryName = category.Name;
         }
         else
         {
             ViewBag.CategoryName = category.Name;
         }
         return View();
     }
 }
Ejemplo n.º 18
0
        public SiteViewModel(StructureContainer context, string contentName)
        {
            Title = SiteSettings.Language == Language.Ru ? "Ракурс" : "Rakurs";
            Context = context;

            var contentList = Context.Content.ToList();
            FetchMainMenuItems(contentList, contentName);

            Content content = null;
            if (!string.IsNullOrEmpty(contentName))
            {
                content = contentList.FirstOrDefault(c => c.Name == contentName);
                if (content == null)
                {
                    throw new HttpNotFoundException();
                }
                IsHomePage = content.MainPage;
            }
            else if (contentName == "")
            {
                content = context.Content.FirstOrDefault(c => c.MainPage);
                IsHomePage = true;
            }

            if (IsHomePage)
            {
                GetGalleryFrameItems();
                GetDiscountBlockItems();
            }

            Content = content;
            if (content != null)
            {
                Title += " - " + (SiteSettings.Language==Language.Ru? content.PageTitle:content.PageTitleEng);
                SeoDescription = content.SeoDescription;
                SeoKeywords = content.SeoKeywords;
            }

        }
Ejemplo n.º 19
0
        public ActionResult Delete(int id)
        {
            using (var context = new StructureContainer())
            {
                var category = context.Category.Include("Children").Include("Products").First(c => c.Id == id);
                while (category.Products.Any())
                {
                    var product = category.Products.First();
                    if (!string.IsNullOrEmpty(product.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource);
                        product.ProductAttributes.Clear();
                        context.DeleteObject(product);
                    }
                }
                context.SaveChanges();

                while (category.Children.Any())
                {
                    int catId = category.Children.First().Id;
                    var child = context.Category.Include("Products").Include("ProductAttributes").First(c => c.Id == catId);
                    child.ProductAttributes.Load();
                    while (child.Products.Any())
                    {
                        var product = child.Products.First();
                        if (!string.IsNullOrEmpty(product.ImageSource))
                        {
                            IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                            IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource);
                            product.ProductAttributes.Clear();
                            context.DeleteObject(product);
                            context.SaveChanges();
                        }
                    }
                    child.Products.Clear();
                    child.ProductAttributes.Clear();
                    context.DeleteObject(child);
                    context.SaveChanges();
                }
                category.ProductAttributes.Load();
                category.ProductAttributes.Clear();
                context.DeleteObject(category);
                context.SaveChanges();
            }
            return RedirectToAction("Index", "Home", new { Area = "", id = "" });
        }
Ejemplo n.º 20
0
 public ActionResult Edit(int id)
 {
     using (var context = new StructureContainer())
     {
         var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == id);
         var attributes = context.ProductAttribute.ToList();
         ViewBag.Attributes = attributes;
         return View(category);
     }
 }
Ejemplo n.º 21
0
        public ActionResult Delete(int id)
        {
            using (var context = new StructureContainer())
            {
                var product = context.Product.Include("Category").First(p => p.Id == id);
                var categoryId = product.Category.Id;
                var category = context.Category.Include("Parent").First(c => c.Id == categoryId);

                if (!string.IsNullOrEmpty(product.ImageSource))
                {
                    IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                    IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource);
                }
                product.ProductAttributes.Clear();
                context.DeleteObject(product);
                context.SaveChanges();

                return category.Parent != null
                   ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name })
                   : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name });
            }
        }
Ejemplo n.º 22
0
        public ActionResult Edit(int id)
        {
            using (var context = new StructureContainer())
            {
                ViewBag.productId = id;
                var product = context.Product.Include("ProductAttributes").Include("Category").First(p => p.Id == id);
                var category = context.Category.Include("Parent").Include("ProductAttributes").First(c => c.Id == product.Category.Id);

                if (category.Parent != null)
                {
                    ViewBag.CategoryName = category.Parent.Name;
                    ViewBag.SubCategoryName = category.Name;
                }
                else
                {
                    ViewBag.CategoryName = category.Name;
                }

                ViewBag.CategoryId = category.Id;
                ViewBag.Attributes = category.ProductAttributes;

                return View(product);
            }
        }
Ejemplo n.º 23
0
        public ActionResult CreateMany(FormCollection form, int categoryId, IList<HttpPostedFileBase> fileUpload, IList<string> titleRU, IList<string> titleEN, IList<string> descriptionRU, IList<string> descriptionEN)
        {
            using (var context = new StructureContainer())
            {
                
                Category category = context.Category.Include("Parent").First(c => c.Id == categoryId);
                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                for (int i = 0; i < 10; i++)
                {
                    if (fileUpload[i] != null)
                    {

                        Product product = new Product {Category = category};

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload[i].FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload[i]);
                        product.ImageSource = fileName;




                        foreach (var kvp in postData)
                        {
                            var attribute = attributes.First(a => a.Id == kvp.Key);
                            if (kvp.Value)
                            {
                                if (!product.ProductAttributes.Contains(attribute))
                                    product.ProductAttributes.Add(attribute);
                            }
                            else
                            {
                                if (product.ProductAttributes.Contains(attribute))
                                    product.ProductAttributes.Remove(attribute);
                            }
                        }


                        product.Title = titleRU[i];
                        product.TitleEng = titleEN[i];
                        product.Description = descriptionRU[i];
                        product.DescriptionEng = descriptionEN[i];

                        context.AddToProduct(product);

                    }
                }

                context.SaveChanges();

                return category.Parent != null
                    ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name })
                    : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name });
            }
        }
Ejemplo n.º 24
0
        public ActionResult Edit(Category model, FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = context.Category.Include("Parent").First(c => c.Id == model.Id);

                TryUpdateModel(category, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "TitleEng",
                                                "SortOrder"
                                            });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);

                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }

                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent != null ? category.Parent.Name : category.Name });
            }
        }
Ejemplo n.º 25
0
 public ActionResult Delete(int id)
 {
     using (var context = new StructureContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         context.DeleteObject(content);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new {area = "", id = ""});
     }
 }