Exemple #1
0
        public PartialViewResult AddComment(CommentFormModel commentFormModel)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ShopContainer())
                {
                    try
                    {
                        Comment comment = new Comment
                                              {
                                                  Date = DateTime.Now,
                                                  Email = commentFormModel.Email,
                                                  IsAdmin = false,
                                                  Name = commentFormModel.Name,
                                                  Phone = commentFormModel.Phone,
                                                  Title = commentFormModel.Title,
                                                  Text = commentFormModel.Text
                                              };

                        context.AddToComment(comment);
                        context.SaveChanges();
                        return PartialView("_Comment", comment);
                    }
                    catch (Exception)
                    {
                        return PartialView("_CommentForm", commentFormModel);
                    }
                }
            }
            return PartialView("_CommentForm", commentFormModel);
        }
Exemple #2
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var article = new Article { Date = DateTime.Now };
                    TryUpdateModel(article, new[]
                                                {
                                                    "Name", 
                                                    "Title", 
                                                    "Published", 
                                                    "SeoDescription", 
                                                    "SeoKeywords"
                                                });
                    article.Text = HttpUtility.HtmlDecode(form["Text"]);

                    context.AddToArticle(article);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemple #3
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile)
        {
            try
            {
                using (var context = new ShopContainer())
                {

                    var brand = new Brand
                                    {
                                        Name = form["Name"], 
                                        Title = form["Title"],
                                        Description = form["Description"], 
                                        SeoDescription = form["SeoDescription"], 
                                        SeoKeywords = form["SeoKeywords"]
                                    };
                    if (uploadFile != null)
                    {
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        uploadFile.SaveAs(filePath);
                        brand.Logo = fileName;
                    }
                    context.AddToBrand(brand);
                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Exemple #4
0
 public ActionResult Details(int id, FormCollection form)
 {
     using (var context = new ShopContainer())
     {
         var order = context.Order.Include("OrderItems").First(o => o.Id == id);
         TryUpdateModel(order, new[] { "Complited", "Info", "Name", "DeliveryAddress", "Email","Phone" });
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Exemple #5
0
 public ActionResult Delete(int id)
 {
     using (var context = new ShopContainer())
     {
         var comment = context.Comment.First(c => c.Id == id);
         context.DeleteObject(comment);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", id = "about" });
     }
 }
Exemple #6
0
        public ActionResult Edit(Content model)
        {
            using (var context = new ShopContainer())
            {
                Content content = context.Content.First(c => c.Id == model.Id);
                TryUpdateModel(content, new[] {"Name","Title","SortOrder","SeoDescription","SeoKeywords"});
                content.Text = HttpUtility.HtmlDecode(model.Text);
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", id = content.Name });
            }


        }
Exemple #7
0
        public ActionResult Delete(int id)
        {
            using (var context = new ShopContainer())
            {
                var order = context.Order.Include("OrderItems").First(o => o.Id == id);

                while (order.OrderItems.Any())
                {
                    var item = order.OrderItems.First();
                    context.DeleteObject(item);
                }

                context.DeleteObject(order);
                context.SaveChanges();
            }
            return RedirectToAction("Index");
        }
Exemple #8
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (var context = new ShopContainer())
         {
             var tag = context.Tag.First(t => t.Id == id);
             TryUpdateModel(tag, new[] {"Name","Title"});
             context.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch
     {
         return View();
     }
 }
 public ActionResult Edit(int id, Category model)
 {
     try
     {
         using (var context = new ShopContainer())
         {
             var category = context.Category.First(c => c.Id == id);
             TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder", "Title" });
             context.SaveChanges();
             return RedirectToAction("Category", "Home", new { area = "", id = category.Name });
         }
     }
     catch
     {
         return View();
     }
 }
Exemple #10
0
        public ActionResult Create(Product model, HttpPostedFileBase fileUpload)
        {

            using (var context = new ShopContainer())
            {
                var category = context.Category.First(c => c.Id == model.CategoryId);



                var product = new Product
                                  {
                                      Name = SiteHelper.UpdatePageWebName(model.Name),
                                      Description = model.Description,
                                      SortOrder = model.SortOrder,
                                      Brand = model.Brand,
                                      Composition = model.Composition,
                                      Size = model.Size,
                                      Price = model.Price,
                                      SeoDescription = model.SeoDescription,
                                      SeoKeywords = model.SeoKeywords,
                                      Title = model.Title
                                  };


                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, 1200);
                    //fileUpload.SaveAs(filePath);
                    product.ImageSource = fileName;
                    product.Preview = fileName;
                }

                product.Category = category;
                context.AddToProduct(product);
                context.SaveChanges();



                return RedirectToAction("Category", "Home", new { area = "", id = category.Name });
            }

        }
Exemple #11
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var tag = new Tag {Name = form["Name"], Title = form["Title"]};
                    context.AddToTag(tag);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Create(ProductAttribute model)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    if (string.IsNullOrEmpty(model.ValueType))
                        model.ValueType = string.Empty;
                    context.AddToProductAttribute(model);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemple #13
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new ShopContainer())
     {
         var article = context.Article.First(c => c.Id == id);
         TryUpdateModel(article,
                       new[]
                            {
                                "Name",
                                "Title",
                                "Published",
                                "SeoDescription",
                                "SeoKeywords"
                            });
         article.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Exemple #14
0
        public ActionResult Create(Category model)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = new Category();
                    TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder", "Title" });
                    context.AddToCategory(category);
                    context.SaveChanges();

                    return RedirectToAction("Category", "Home", new { area = "", id = category.Name });
                }
                
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Edit(int id, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var productAttribute = context.ProductAttribute.First(pa => pa.Id == id);
                try
                {
                    TryUpdateModel(productAttribute, new[] { "Name", "SortOrder", "ShowInCommonView" ,"Static"});
                    productAttribute.ValueType = string.IsNullOrEmpty(productAttribute.ValueType) ? string.Empty : form["ValueType"];
                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch
                {

                }
                return View(productAttribute);
            }

        }
Exemple #16
0
 public ActionResult Create(FormCollection form)
 {
     using (var context = new ShopContainer())
     {
         var content = new Content();
         TryUpdateModel(content,
                        new[]
                            {
                                "Name",
                                "Title",
                                "PageTitle",
                                "SortOrder",
                                "Published",
                                "MainPage",
                                "SeoText",
                                "SeoDescription",
                                "SeoKeywords"
                            });
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.AddToContent(content);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Exemple #17
0
        public ActionResult Tags(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.First(p => p.Id == productId);
                PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId");
                product.Tags.Clear();
                foreach (KeyValuePair<int, bool> kvp in cbData)
                {
                    if (kvp.Value)
                    {
                        var tagId = kvp.Key;
                        var tag = context.Tag.First(t => t.Id == tagId);
                        product.Tags.Add(tag);
                    }
                }
                context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Exemple #18
0
        public ActionResult Images(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.Include("ProductImages").First(p => p.Id == productId);
                ViewBag.ProductTitle = product.Title;
                ViewBag.ProductId = product.Id;

                if (!string.IsNullOrEmpty(form["r_default"]))
                {
                    var defaultImageId = Convert.ToInt32(form["r_default"]);
                    product.ProductImages.ToList().ForEach(p => p.Default = false);
                    product.ProductImages.First(image => image.Id == defaultImageId).Default = true;
                    context.SaveChanges();
                }

                return View(product.ProductImages);
            }

        }
Exemple #19
0
        public ActionResult Edit(int brandId, int categoryId, int id, FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var brand = context.Brand.First(b => b.Id == brandId);
                    var category = context.Category.First(c => c.Id == categoryId);

                    var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == id);
                    product.Brand = brand;

                    if (product.Category.Id != category.Id)
                    {
                        product.ProductAttributeValues.Clear();
                        product.Category = category;
                    }


                    TryUpdateModel(product,
                        new[]
                        {
                            "Name",
                            "Title",
                            "SortOrder",
                            "Price", 
                            "OldPrice",
                            "IsNew",
                            "IsSpecialOffer",
                            "Published",
                            "SeoDescription",
                            "SeoKeywords",
                            "Articul"
                        });

                    product.ShortDescription = HttpUtility.HtmlDecode(form["ShortDescription"]);
                    product.Description = HttpUtility.HtmlDecode(form["Description"]);

                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Exemple #20
0
        public ActionResult Attributes(int categoryId, FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = context.Category.Include("ProductAttributes").First(c => c.Id == categoryId);
                    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 (!category.ProductAttributes.Contains(attribute))
                                category.ProductAttributes.Add(attribute);
                        }
                        else
                        {
                            if (category.ProductAttributes.Contains(attribute))
                                category.ProductAttributes.Remove(attribute);
                        }
                    }

                    context.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Exemple #21
0
        public ActionResult Create(int? parentId, FormCollection form, HttpPostedFileBase uploadFile)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = new Category();
                    TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder","Title" });

                    if (uploadFile != null)
                    {
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        uploadFile.SaveAs(filePath);
                        category.ImageSource = fileName;
                    }


                    if (parentId.HasValue)
                    {
                        var parent = context.Category.First(c => c.Id == parentId);
                        parent.Children.Add(category);
                    }
                    else
                    {
                        context.AddToCategory(category);
                    }
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemple #22
0
        public ActionResult Edit(int id, FormCollection form, HttpPostedFileBase uploadFile)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = context.Category.First(c => c.Id == id);
                    TryUpdateModel(category, new[] { "Name", "SeoDescription", "SeoKeywords", "SortOrder", "Title" });

                    if (uploadFile != null)
                    {
                        if (!string.IsNullOrEmpty(category.ImageSource))
                        {
                            IOHelper.DeleteFile("~/Content/Images", category.ImageSource);
                            
                            foreach (var folder in GraphicsHelper.ThumbnailFolders)
                            {
                                IOHelper.DeleteFile("~/ImageCache/" + folder, category.ImageSource);
                            }
                        }

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        uploadFile.SaveAs(filePath);
                        category.ImageSource = fileName;
                    }

                    context.SaveChanges();
                }
                return RedirectToAction("Index");

            }
            catch
            {
                return View();
            }
        }
Exemple #23
0
        public ActionResult Delete(int id)
        {
            using (var context = new ShopContainer())
            {
                var category = context.Category.Include("ProductAttributes").First(c => c.Id == id);
                if (!string.IsNullOrEmpty(category.ImageSource))
                {
                    IOHelper.DeleteFile("~/Content/Images", category.ImageSource);

                    foreach (var folder in GraphicsHelper.ThumbnailFolders)
                    {
                        IOHelper.DeleteFile("~/ImageCache/" + folder, category.ImageSource);
                    }
                }
                category.ProductAttributes.Clear();
                context.DeleteObject(category);
                context.SaveChanges();
                return RedirectToAction("Index");
            }
        }
Exemple #24
0
        //
        // GET: /Admin/Tag/Delete/5

        public ActionResult Delete(int id)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var tag = context.Tag.First(t => t.Id == id);
                    context.DeleteObject(tag);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return RedirectToAction("Index");
            }
        }
Exemple #25
0
        public ActionResult AddImage(int productId, FormCollection form, IEnumerable<HttpPostedFileBase> uploadFiles)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.First(p => p.Id == productId);

                foreach (var file in uploadFiles)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    product.ProductImages.Add(new ProductImage { ImageSource = fileName });
                }
                context.SaveChanges();
            }
            return RedirectToAction("Images", new { id = productId });
        }
Exemple #26
0
 public ActionResult DeleteImage(int id, int productId)
 {
     using (var context = new ShopContainer())
     {
         var image = context.ProductImage.First(i => i.Id == id);
         DeleteImage(image, context);
         context.SaveChanges();
         return RedirectToAction("Images", new { id = productId });
     }
 }
Exemple #27
0
        public ActionResult Delete(int id)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.Include("ProductAttributeValues").Include("ProductAttributeStaticValues").First(p => p.Id == id);
                product.ProductAttributeValues.Clear();

                while (product.ProductAttributeStaticValues.Any())
                {
                    var pav = product.ProductAttributeStaticValues.First();
                    context.DeleteObject(pav);
                }

                while (product.ProductImages.Any())
                {
                    var image = product.ProductImages.First();
                    DeleteImage(image, context);
                }

                product.Tags.Clear();
                context.DeleteObject(product);
                context.SaveChanges();
                return RedirectToAction("Index");
            }
        }
Exemple #28
0
        public ActionResult Attributes(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == productId);

                PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId");
                PostData staticAttrData = form.ProcessPostData("tb", "productId");

                product.ProductAttributeValues.Clear();

                foreach (var kvp in cbData)
                {
                    var attributeValueId = kvp.Key;
                    bool attributeValue = kvp.Value;

                    if (attributeValue)
                    {
                        var productAttributeValue = context.ProductAttributeValues.First(pv => pv.Id == attributeValueId);
                        product.ProductAttributeValues.Add(productAttributeValue);
                    }
                }


                foreach (var kvp in staticAttrData)
                {
                    int attributeId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        string attributeValue = value.Value;

                        var productAttribute = context.ProductAttribute.Include("ProductAttributeStaticValues").First(pa => pa.Id == attributeId);

                        //productAttribute.ProductAttributeStaticValues.Clear();

                        ProductAttributeStaticValues productAttributeValue = null;
                        productAttributeValue = context.ProductAttributeStaticValues.FirstOrDefault(
                                pav => pav.ProductAttribute.Id == productAttribute.Id && pav.Product.Id == product.Id);


                        if (string.IsNullOrEmpty(attributeValue))
                        {
                            if (productAttributeValue != null)
                                context.DeleteObject(productAttributeValue);
                        }
                        else
                        {
                            if (productAttributeValue == null)
                            {



                                productAttributeValue = new ProductAttributeStaticValues
                                                            {
                                                                Value = attributeValue,
                                                                ProductAttribute = productAttribute
                                                            };
                                product.ProductAttributeStaticValues.Add(productAttributeValue);

                            }
                            else
                            {
                                productAttributeValue.Value = attributeValue;
                            }
                        }
                        //productAttribute.ProductAttributeValues.Add(productAttributeValue);


                    }
                }

                context.SaveChanges();




                return RedirectToAction("Index");
            }
        }
Exemple #29
0
        public ActionResult CheckOut(FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                Order order = new Order
                {
                    DeliveryAddress = form["Order.DeliveryAddress"],
                    Email = form["Order.Email"],
                    Name = form["Order.Name"],
                    OrderDate = DateTime.Now,
                    Phone = form["Order.Phone"],
                    Complited = false
                };

                foreach (var orderItem in WebSession.OrderItems.Select(o => o.Value))
                {
                    order.OrderItems.Add(orderItem);
                }


                if (order.OrderItems.Any())
                {
                    context.AddToOrder(order);
                    context.SaveChanges();
                    SendEmail(order);
                    WebSession.OrderItems.Clear();
                }

                using (var siteContext = new ShopContainer())
                {
                    var model = new SiteModel(siteContext, null);
                    ViewBag.MainMenu = model.Menu;
                    ViewBag.CatalogueMenu = model.CatalogueMenu;
                    model.Title += " - Ваш заказ оформлен";
                    this.SetSeoContent(model);
                    return View("ThankYou", model);
                }
            }

        }
Exemple #30
0
        public ActionResult Prices(FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var products = context.Product.Include("Brand").Include("Category").ToList();

                PostCheckboxesData cbDataNew = form.ProcessPostCheckboxesData("new");
                PostCheckboxesData cbDataSpec = form.ProcessPostCheckboxesData("special");
                PostCheckboxesData cbDataPublish = form.ProcessPostCheckboxesData("publish");
                PostData oldPriceData = form.ProcessPostData("oldprice");
                PostData priceData = form.ProcessPostData("price");

                foreach (var kvp in cbDataNew)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).IsNew = productValue;
                }

                foreach (var kvp in cbDataSpec)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).IsSpecialOffer = productValue;
                }

                foreach (var kvp in cbDataPublish)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).Published = productValue;
                }

                foreach (var kvp in oldPriceData)
                {
                    int productId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        var productValue = Convert.ToDecimal(value.Value);
                        products.First(p => p.Id == productId).OldPrice = productValue;
                    }
                }

                foreach (var kvp in priceData)
                {
                    int productId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        var productValue = Convert.ToDecimal(value.Value);
                        products.First(p => p.Id == productId).Price = productValue;
                    }
                }

                context.SaveChanges();
            }
            return RedirectToAction("Prices");
        }