Esempio n. 1
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");
        }
Esempio n. 2
0
        public string Add(int id)
        {

            const string prefix = "В корзине ";

            if (WebSession.OrderItems.ContainsKey(id))
                WebSession.OrderItems[id].Quantity++;
            else
            {
                using (var context = new ShopContainer())
                {
                    var product = context.Product.Include("Category").First(p => p.Id == id);
                    OrderItem orderItem = new OrderItem
                    {
                        Description = product.Description,
                        ImageSource = product.ImageSource,
                        Price = product.Price,
                        ProductId = product.Id,
                        ProductName = product.Name,
                        Quantity = 1,
                        ProductTitle = product.Title,
                        CategoryName = product.Category.Name,
                        CategoryTitle = product.Category.Title
                    };

                    WebSession.OrderItems.Add(product.Id, orderItem);
                }
            }

            int quantity = WebSession.OrderItems.Sum(o => o.Value.Quantity);

            return prefix+" " + quantity +" "+ TextHelper.GetQuantitySufix(quantity);
            // WebSession.OrderItems.Sum(o => o.Value.Quantity);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
0
 public ActionResult Index()
 {
     using (var context = new ShopContainer())
     {
         return View();
     }
 }
 public ActionResult Delete(int id)
 {
     using (var context = new ShopContainer())
     {
         try
         {
             var attribute = context.ProductAttribute.Include("ProductAttributeValues").First(a => a.Id == id);
             while (attribute.ProductAttributeValues.Any())
             {
                 var pav = attribute.ProductAttributeValues.First();
                 pav.Products.Clear();
                 context.DeleteObject(pav);
             }
             attribute.Categories.Clear();
             context.DeleteObject(attribute);
             context.SaveChanges();
             return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
             ViewBag.ErrorMessage = ex.Message +"<br/>"+ ex.InnerException.Message;
             var productAttributes = context.ProductAttribute.Include("ProductAttributeValues").ToList();
             return View("Index", productAttributes);
         }
     }
 }
Esempio n. 7
0
        public int Add(int id)
        {
            if (WebSession.OrderItems.ContainsKey(id))
                WebSession.OrderItems[id].Quantity++;
            else
            {
                using (var context = new ShopContainer())
                {
                    var product = context.Product.Include("Category").Include("ProductImages").First(p => p.Id == id);
                    var image = product.ProductImages.Where(i => i.Default).FirstOrDefault();
                    OrderItem orderItem = new OrderItem
                                              {
                                                  Description = product.Description,
                                                  Image = (image != null) ? image.ImageSource : null,
                                                  Price = product.Price,
                                                  ProductId = product.Id,
                                                  ProductName = product.Name,
                                                  Quantity = 1,
                                                  Name = product.Title,
                                                  CategoryName = product.Category.Name
                                              };

                    WebSession.OrderItems.Add(product.Id, orderItem);
                }
            }
            return WebSession.OrderItems.Sum(o=>o.Value.Quantity);
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
0
        public ShopModel(ShopContainer context, string categoryId, int? productId)
            : base(context, null)
        {

            Category = context.Category.Include("Products").First(c => c.Name == categoryId);

            foreach (var item in CatalogueMenu.Where(item => item.ContentName == Category.Name))
            {
                if (productId != null)
                {
                    item.Selected = true;
                }
                else
                {
                    item.Current = true;
                }
            }

            if (!string.IsNullOrEmpty(Category.SeoDescription))
                SeoDescription = Category.SeoDescription;
            if (!string.IsNullOrEmpty(Category.SeoKeywords))
                SeoKeywords = Category.SeoKeywords;


            if (productId.HasValue)
            {
                Product = context.Product.First(p => p.Id == productId);
            }

        }
Esempio n. 10
0
        public SiteModel(ShopContainer context, string contentId)
        {
            Title = "Bikini";

            Menu = new Menu();
            

            Content = context.Content.FirstOrDefault(c => c.Name == contentId) ?? context.Content.First(c => c.MainPage);

            var contents = context.Content.ToList();
            foreach (var c in contents.OrderBy(c => c.SortOrder))
            {
                Menu.Add(new MenuItem { ContentId = c.Id, ContentName = c.Name , Current = c.Name==Content.Name&&contentId!=null,SortOrder = c.SortOrder,Title = c.Title});
            }
            CatalogueMenu = new Menu();
            
            var categories = context.Category.ToList();
            
            foreach (var c in categories)
            {
                CatalogueMenu.Add(new MenuItem { ContentId = c.Id, ContentName = c.Name, SortOrder = c.SortOrder, Title = c.Title });
            }

            IsHomePage = Content.MainPage;
            SeoDescription = Content.SeoDescription;
            SeoKeywords = Content.SeoKeywords;
        }
Esempio n. 11
0
        //
        // GET: /Admin/Tag/

        public ActionResult Index()
        {
            using (var context = new ShopContainer())
            {
                var tags = context.Tag.ToList();
                return View(tags);
            }
        }
Esempio n. 12
0
        //
        // GET: /Admin/Brand/

        public ActionResult Index()
        {
            using (var context = new ShopContainer())
            {
                var brands = context.Brand.ToList();
                return View(brands);
            }
        }
Esempio n. 13
0
 public ActionResult Prices()
 {
     using (var context = new ShopContainer())
     {
         var products = context.Product.Include("Brand").Include("Category").ToList();
         return View(products);
     }
 }
Esempio n. 14
0
 public ActionResult Edit(int id)
 {
     using (var context = new ShopContainer())
     {
         var category = context.Category.First(c => c.Id == id);
         return View(category);
     }
 }
 public ActionResult Edit(int id)
 {
     using (var context = new ShopContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == id);
         return View(productAttribute);
     }
 }
        //
        // GET: /Admin/ProductAttribute/

        public ActionResult Index()
        {
            using (var context = new ShopContainer())
            {
                var productAttributes = context.ProductAttribute.Include("ProductAttributeValues").ToList();
                return View(productAttributes);
            }
        }
Esempio n. 17
0
        //
        // GET: /Admin/Tag/Edit/5

        public ActionResult Edit(int id)
        {
            using (var context = new ShopContainer())
            {
                var tag = context.Tag.First(t => t.Id == id);
                return View(tag);
            }
        }
Esempio n. 18
0
 public ActionResult Edit(int id)
 {
     using (var context = new ShopContainer())
     {
         Content content = context.Content.First(c => c.Id == id);
         return View(content);
     }
 }
Esempio n. 19
0
        //
        // GET: /Admin/WishList/

        public ActionResult Index()
        {
            using (var context = new ShopContainer())
            {
                var wishList = context.Wish.ToList();
                return View(wishList);
            }
        }
Esempio n. 20
0
 public ActionResult Index()
 {
     using (var context = new ShopContainer())
     {
         var orders = context.Order.Include("OrderItems").ToList();
         return View(orders);
     }
 }
Esempio n. 21
0
        //
        // GET: /Admin/Brand/Details/5

        public ActionResult Details(int id)
        {
            using (var context = new ShopContainer())
            {
                var brand = context.Brand.Where(b => b.Id == id).First();
                return View(brand);
            }
        }
Esempio n. 22
0
 public ActionResult Details(int id)
 {
     using (var context = new ShopContainer())
     {
         var order = context.Order.Include("OrderItems").First(o => o.Id == id);
         return View(order);
     }
 }
Esempio n. 23
0
 public ActionResult Edit(int id)
 {
     using (var context = new ShopContainer())
     {
         var article = context.Article.First(c => c.Id == id);
         return View(article);
     }
 }
Esempio n. 24
0
        //
        // GET: /Admin/Article/

        public ActionResult Index()
        {
            using (var context = new ShopContainer())
            {
                var articles = context.Article.ToList();
                return View(articles);
            }
        }
Esempio n. 25
0
 public ActionResult NotFound()
 {
     using (var context = new ShopContainer())
     {
         SiteViewModel model = new SiteViewModel(context, null);
         ViewBag.MainMenu = model.MainMenu;
         return View(model);
     }
 }
Esempio n. 26
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");
 }
Esempio n. 27
0
 public ActionResult ProductDetails(string id, string category)
 {
     using (var context = new ShopContainer())
     {
         ShopViewModel model = new ShopViewModel(context, category, null, null, id, null, null, null);
         this.SetSeoContent(model);
         ViewBag.MainMenu = model.MainMenu;
         return View(model);
     }
 }
Esempio n. 28
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" });
     }
 }
Esempio n. 29
0
        //
        // GET: /Account/LogOn

        public ActionResult LogOn()
        {
            using (var context = new ShopContainer())
            {
                SiteViewModel model = new SiteViewModel(context, null);
                this.SetSeoContent(model);
                ViewBag.MainMenu = model.MainMenu;
                return View();
            }
        }
Esempio n. 30
0
 public ActionResult CheckOut()
 {
     using (var context = new ShopContainer())
     {
         var model = new SiteViewModel(context, null);
         ViewBag.MainMenu = model.MainMenu;
         model.Title = "Магазин детских игрушек Toy-Planet - Оформление заказа";
         this.SetSeoContent(model);
         return View(model);
     }
 }