Example #1
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 = "" });
            }
        }
Example #2
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 = "" });
            }
        }
 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");
     }
 }
 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");
 }
Example #5
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 });
            }
        }
Example #6
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
                                            });
            }
        }
        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");
        }
Example #8
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 });
            }
        }
Example #9
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 });
            }
        }
Example #10
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 = ""});
     }
 }
Example #11
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 });
            }
        }
Example #12
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 = "" });
        }