Example #1
0
        public ActionResult SelectedCategory(string sex, string type, string category)
        {
            Sex          _sex;
            ClothingType _type;

            if (sex == "male")
            {
                _sex = Sex.Male;
            }
            else
            {
                _sex = Sex.Female;
            }

            if (type == "cloth")
            {
                _type = ClothingType.Cloth;
            }
            else
            {
                _type = ClothingType.Shoes;
            }

            List <Item> items = new List <Item>();

            using (InternetStoreContext db = new InternetStoreContext())
            {
                items = db.Items.Include(x => x.Images).Include(x => x.Category).Where(x => x.Category.Name == category & (x.Sex == _sex | x.Sex == Sex.Unisex) & x.ClothingType == _type & x.Archive == false).ToList();
            }
            return(View(items));
        }
Example #2
0
        public ActionResult Details(Item item, string sex, string type)
        {
            using (InternetStoreContext db = new InternetStoreContext())
            {
                if (type == "одежда")
                {
                    item.ClothingType = ClothingType.Cloth;
                }
                else
                {
                    item.ClothingType = ClothingType.Shoes;
                }

                if (sex == "мужское")
                {
                    item.Sex = Sex.Male;
                }
                else if (sex == "женское")
                {
                    item.Sex = Sex.Female;
                }
                else
                {
                    item.Sex = Sex.Unisex;
                }

                db.Items.Attach(item);
                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Example #3
0
        public ActionResult PurchaseInfo(Client client)
        {
            if (!ModelState.IsValid)
            {
                return(View("PurchaseInfo", client));
            }
            using (InternetStoreContext db = new InternetStoreContext())
            {
                db.Clients.Add(client);
                Purchase purchase = new Purchase();
                purchase.Client = client;
                foreach (var item in MyCart.GetInstance().Cart)
                {
                    var it = db.Items.FirstOrDefault(x => x.Id == item.Id);
                    if (it != null)
                    {
                        var _size = it.Sizes.FirstOrDefault(x => x.MySize == item.SizeName);
                        if (_size != null)
                        {
                            _size.Count -= item.Quantity;
                        }
                    }
                    item.Archive = true;
                    purchase.Items.Add(item);
                }
                purchase.PurchaseDateTime = DateTime.Now;

                db.Purchases.Add(purchase);

                db.SaveChanges();

                MyCart.GetInstance().Cart.Clear();
            }
            return(RedirectToAction("ShowCart"));
        }
Example #4
0
 public ActionResult Catalog()
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         ViewBag.SexList = Enum.GetValues(typeof(Sex));
     }
     return(View());
 }
Example #5
0
        public ActionResult Index()
        {
            List <Item> items;

            using (InternetStoreContext db = new InternetStoreContext())
            {
                items = db.Items.Include(x => x.Images).Include(x => x.Category).Where(x => x.Archive == false).ToList();
            }
            return(View(items));
        }
Example #6
0
        public ActionResult Details(int id)
        {
            Item item;

            using (InternetStoreContext db = new InternetStoreContext())
            {
                item = db.Items.Include(x => x.Images).Include(x => x.Category).Include(x => x.Sizes).FirstOrDefault(x => x.Id == id);
            }
            return(View(item));
        }
Example #7
0
        public ActionResult Index()
        {
            List <Category> categories = new List <Category>();

            using (InternetStoreContext db = new InternetStoreContext())
            {
                categories = db.Categories.ToList();
            }
            return(View(categories));
        }
Example #8
0
 public ActionResult DeleteSize(int sizeid, int id)
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         var size = db.Sizes.FirstOrDefault(x => x.Id == sizeid);
         if (size != null)
         {
             db.Sizes.Remove(size);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Details", new { id = id }));
 }
Example #9
0
 public ActionResult AddImage(int itemid, string url)
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         var item = db.Items.FirstOrDefault(x => x.Id == itemid);
         item.Images.Add(new Image()
         {
             Path = url
         });
         db.SaveChanges();
     }
     return(RedirectToAction("Details", new { id = itemid }));
 }
Example #10
0
 public ActionResult Delete(int id)
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         var item = db.Items.FirstOrDefault(x => x.Id == id);
         if (item != null)
         {
             db.Items.Remove(item);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult NavbarPartial()
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         var menCloth   = db.Items.Include(c => c.Category).Where(x => (x.Sex == Sex.Male || x.Sex == Sex.Unisex) & x.ClothingType == ClothingType.Cloth).Select(x => x.Category).Distinct().ToList();
         var menShoes   = db.Items.Include(c => c.Category).Where(x => (x.Sex == Sex.Male || x.Sex == Sex.Unisex) & x.ClothingType == ClothingType.Shoes).Select(x => x.Category).Distinct().ToList();
         var womenCloth = db.Items.Include(c => c.Category).Where(x => (x.Sex == Sex.Female || x.Sex == Sex.Unisex) & x.ClothingType == ClothingType.Cloth).Select(x => x.Category).Distinct().ToList();
         var womenShoes = db.Items.Include(c => c.Category).Where(x => (x.Sex == Sex.Female || x.Sex == Sex.Unisex) & x.ClothingType == ClothingType.Shoes).Select(x => x.Category).Distinct().ToList();
         ViewBag.MenCloth   = menCloth;
         ViewBag.WomenCloth = womenCloth;
         ViewBag.MenShoes   = menShoes;
         ViewBag.WomenShoes = womenShoes;
     }
     return(PartialView());
 }
Example #12
0
 public ActionResult AddSize(string mysize, int count, int id)
 {
     using (InternetStoreContext db = new InternetStoreContext())
     {
         var item = db.Items.FirstOrDefault(x => x.Id == id);
         if (item != null)
         {
             item.Sizes.Add(new Size()
             {
                 MySize = mysize, Count = count
             });
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Details", new { id = id }));
 }
Example #13
0
        public ActionResult DeleteImage(int imageid)
        {
            int itemid = 0;

            using (InternetStoreContext db = new InternetStoreContext())
            {
                var item = db.Images.FirstOrDefault(x => x.Id == imageid);
                if (item != null)
                {
                    itemid = item.ItemId;
                    db.Images.Remove(item);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Details", new { id = itemid }));
        }
Example #14
0
        public ActionResult Create(Item item, string path, string sex, string type)
        {
            using (InternetStoreContext db = new InternetStoreContext())
            {
                if (type == "одежда")
                {
                    item.ClothingType = ClothingType.Cloth;
                }
                else
                {
                    item.ClothingType = ClothingType.Shoes;
                }

                if (sex == "мужское")
                {
                    item.Sex = Sex.Male;
                }
                else if (sex == "женское")
                {
                    item.Sex = Sex.Female;
                }
                else
                {
                    item.Sex = Sex.Unisex;
                }

                item.Images.Add(new Image {
                    Path = path
                });

                var category = db.Categories.FirstOrDefault(x => x.Name == item.Category.Name);
                if (category == null)
                {
                    category = new Category()
                    {
                        Name = item.Category.Name
                    }
                }
                ;

                item.Category = category;
                db.Items.Add(item);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Example #15
0
        public ActionResult AddToCart(int Id, int quantity, string size)
        {
            size = size.Replace("\r\n", "").Trim();
            Item item;

            using (InternetStoreContext db = new InternetStoreContext())
            {
                item = db.Items.FirstOrDefault(x => x.Id == Id);
            }
            if (item != null)
            {
                item.Quantity = quantity;
                item.SizeName = size;
            }

            MyCart.GetInstance().Cart.Add(item);

            return(RedirectToAction("Index"));
        }
Example #16
0
 public PurchasesController()
 {
     db = new InternetStoreContext();
 }