Exemple #1
0
        public SiteViewModel(SiteContainer context, string categoryName)
        {
            var categories = context.Category;
            Menu = InitializeMainMenu(categories, categoryName);


        }
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == id);
         return View(productAttribute);
     }
 }
Exemple #3
0
 public ActionResult About()
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First();
         return PartialView("_About", content);
     }
 }
Exemple #4
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         return View(content);
     }
 }
Exemple #5
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         Article article = context.Article.First(a => a.Id == id);
         return View(article);
     }
 }
Exemple #6
0
 public ActionResult Articles()
 {
     using (var context = new SiteContainer())
     {
         var articles = context.Article.ToList();
         return PartialView("_Articles", articles);
     }
 }
        //
        // GET: /Admin/ProductAttributes/

        public ActionResult Index()
        {
            using (var context = new SiteContainer())
            {
                var attributes = context.ProductAttribute.ToList();
                return View(attributes);
            }
        }
Exemple #8
0
 public ActionResult NotFound()
 {
     using (var context = new SiteContainer())
     {
         var model = new SiteViewModel(context, null);
         this.SetSeoContent(model);
         return View(model);
     }
 }
 public ActionResult Create()
 {
     using (var context = new SiteContainer())
     {
         var category = new Category { SortOrder = 0 };
         var attributes = context.ProductAttribute.ToList();
         ViewBag.Attributes = attributes;
         return View(category);
     }
 }
Exemple #10
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         Article article = context.Article.First(a => a.Id == id);
         context.DeleteObject(article);
         context.SaveChanges();
     }
     return RedirectToAction("Index", "Home", new { Area = "", id = "" });
 }
 public ActionResult Edit(ProductAttribute model, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == model.Id);
         TryUpdateModel(productAttribute, new[] { "Title" });
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Exemple #12
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var category = context.Category.Include("ProductAttributes").First(c => c.Id == id);
         var attributes = context.ProductAttribute.ToList();
         ViewBag.Attributes = attributes;
         return View(category);
     }
 }
Exemple #13
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         TryUpdateModel(content, new[] {"Title"});
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Catalogue", new {Area = "", id = ""});
     }
 }
Exemple #14
0
        //
        // GET: /Admin/Product/Create

        public ActionResult Create(int id)
        {
            using (var context = new SiteContainer())
            {
                var category = context.Category.Include("ProductAttributes").First(c => c.Id == id);
                ViewBag.CategoryId = category.Id;
                ViewBag.Attributes = category.ProductAttributes;
                ViewBag.CategoryName = category.Name;
                return View();
            }
        }
 public ActionResult Create(ProductAttribute model)
 {
     using (var context = new SiteContainer())
     {
         var pa = new ProductAttribute();
         TryUpdateModel(pa, new[] { "Title" });
         context.AddToProductAttribute(pa);
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
 public ActionResult ShowFilter(string id)
 {
     using (var context = new SiteContainer())
     {
         var model = new CatalogueViewModel(context, id);
         ViewBag.CategoryName = model.Category.Name;
         ViewBag.CategoryTitle = model.Category.Title;
         ViewBag.CategoryId = model.Category.Id;
         return PartialView("_SearchCriteriaSelector", model.Attributes);
     }
     
 }
        //
        // GET: /Catalogue/

        public ActionResult Index(string id)
        {
            using (var context = new SiteContainer())
            {
                var model = new CatalogueViewModel(context, id);
                this.SetSeoContent(model);

                if (WebSession.Categories.ContainsKey(model.Category.Id))
                    model.ApplyFilterForProducts(WebSession.Categories[model.Category.Id]);

                return View(model);
            }
        }
Exemple #18
0
        //
        // GET: /Admin/Product/Edit/5

        public ActionResult Edit(int id)
        {
            using (var context = new SiteContainer())
            {
                ViewBag.productId = id;
                var product = context.Product.Include("ProductAttributes").Include("Category").First(p => p.Id == id);
                var category = context.Category.Include("ProductAttributes").First(c => c.Id == product.Category.Id);
                ViewBag.CategoryName = category.Name;
                ViewBag.CategoryId = category.Id;
                ViewBag.Attributes = category.ProductAttributes;

                return View(product);
            }
        }
        public ActionResult Index(string id, FormCollection form)
        {
            using (var context = new SiteContainer())
            {
                var model = new CatalogueViewModel(context, id);
                this.SetSeoContent(model);

                List<ProductAttribute> checkedAttributes = (from attribute in model.Attributes where form["attr_" + attribute.Id] == "true,false" select attribute).ToList();
                WebSession.Categories[model.Category.Id] = checkedAttributes;

                if (WebSession.Categories.ContainsKey(model.Category.Id))
                    model.ApplyFilterForProducts(WebSession.Categories[model.Category.Id]);

                return View(model);
            }
        }
Exemple #20
0
        public ActionResult Create(FormCollection form, int categoryId, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContainer())
            {
                Product product = new Product();
                Category category = context.Category.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", "Description" });

                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);
                    fileUpload.SaveAs(filePath);

                    product.ImageSource = fileName;
                }

                context.AddToProduct(product);

                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                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");
        }
Exemple #22
0
 public ActionResult Edit(int id, FormCollection form)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             Article article = context.Article.First(a => a.Id == id);
             TryUpdateModel(article, new[] { "Title", "Date" });
             article.Text = HttpUtility.HtmlDecode(form["Text"]);
             context.SaveChanges();
         }
         return RedirectToAction("Index", "Home", new { Area = "", id = "" });
     }
     catch
     {
         return View();
     }
 }
Exemple #23
0
        public void FeedbackForm(FeedbackFormModel feedbackFormModel)
        {
            using (var context = new SiteContainer())
            {
                var emails = new List<MailAddress>
                                 {
                                     new MailAddress("*****@*****.**")
                                 };

                var responseData = Helpers.MailHelper.SendTemplate(null, emails, "Форма обратной связи", null, null, true, feedbackFormModel.Name, feedbackFormModel.Email, feedbackFormModel.Text);
                var responseFeedback = new Feedback
                                           {
                                               Email = feedbackFormModel.Email,
                                               ErrorMessage = responseData.ErrorMessage,
                                               Text = feedbackFormModel.Text,
                                               Title = feedbackFormModel.Name,
                                               Sent = responseData.EmailSent
                                           };

                context.AddToFeedback(responseFeedback);
                context.SaveChanges();
            }
        }
Exemple #24
0
        public ActionResult Create(FormCollection form)
        {
            using (var context = new SiteContainer())
            {
                var category = new Category();


                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr");
                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", 
                    "SortOrder", 
                    "SeoDescription", 
                    "SeoKeywords" });

                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }
Exemple #25
0
        public CatalogueViewModel(SiteContainer context, string categoryName)
            : base(context, categoryName)
        {
            // TODO: сделать дефолтный пункт меню
            if (categoryName == null)
                categoryName = "sceneries";
            //
            var category = context.Category.Include("ProductAttributes").Include("Products").FirstOrDefault(c => c.Name == categoryName || categoryName == null);
            if (category == null)
            {
                throw new HttpNotFoundException("page " + categoryName);
            }

            if (categoryName == null)
                foreach (var item in Menu.Where(c => c.ContentId == category.Id))
                {
                    item.Current = true;
                }

            Title = category.Title;
            Category = category;
            Products = category.Products;
            Attributes = category.ProductAttributes != null ? category.ProductAttributes.ToList() : new List<ProductAttribute>();
        }
Exemple #26
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var category = context.Category.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();

                category.ProductAttributes.Load();
                category.ProductAttributes.Clear();
                context.DeleteObject(category);
                context.SaveChanges();
            }
            return RedirectToAction("Index", "Home", new { Area = "", id = "" });
        }
Exemple #27
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var product = context.Product.Include("Category").First(p => p.Id == id);
                var categoryId = product.Category.Id;
                var category = context.Category.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 RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }