Example #1
0
        public void CreateNewGood(string name, int place, int amount, string provider)
        {
            Good good = new Good();

            good.Name         = name;
            good.StoragePlace = place;
            good.Amount       = amount;
            if (provider.Length > 0)
            {
                good.ProviderID = _context.Providers.Single(x => x.Name == provider).ProviderID;
            }

            _context.Goods.Add(good);
            _context.SaveChanges();
        }
        private void updateProductList(int id, int sizeId, string func, int sizeAlter = 0, string sortOrder = "#")
        {
            IEnumerable <Product> products = this.db.Product; //

            products = products.Where(s => s.name.Contains(search) ||
                                      s.supplier.Contains(search));              //
            IEnumerable <ProductSize> sizes = this.db.ProductSize;

            sizes = sizes.Where(s => s.product == this.aProducts.choosenProduct.id);
            for (int i = 0; i < pSortParams.Length; i++)
            {
                if (pSortParams[i].Contains(sortOrder))
                {
                    pSortParams[i] = sortOrder + (pSortParams[i].Contains("_asc") ? "_desc" : "_asc");
                    switch (pSortParams[i])
                    {
                    case "cat_desc":
                        products = products.OrderByDescending(p => p.category);
                        break;

                    case "cat_asc":
                        products = products.OrderBy(p => p.category);
                        break;

                    case "sup_desc":
                        products = products.OrderByDescending(p => p.supplier);
                        break;

                    case "sup_asc":
                        products = products.OrderBy(p => p.supplier);
                        break;

                    case "price_desc":
                        products = products.OrderByDescending(p => p.price);
                        break;

                    case "price_asc":
                        products = products.OrderBy(p => p.price);
                        break;

                    case "name_desc":
                        products = products.OrderByDescending(p => p.name);
                        break;

                    case "name_asc":
                        products = products.OrderBy(p => p.name);
                        break;

                    case "size_desc":
                        sizes = sizes.OrderByDescending(p => p.size);
                        break;

                    case "size_asc":
                        sizes = sizes.OrderBy(p => p.size);
                        break;

                    case "quantity_desc":
                        sizes = sizes.OrderByDescending(p => p.quantity);
                        break;

                    case "quantity_asc":
                        sizes = sizes.OrderBy(p => p.quantity);
                        break;
                    }
                }
            }
            this.aProducts.products = products.Skip((pPageInfor.pageIndex - 1) * pPageInfor.pageSize).Take(pPageInfor.pageSize);
            this.aProducts.sizes    = sizes;

            if (func == "details")
            {
                this.aProducts.choosenProduct = db.Product.Where(p => p.id == id).FirstOrDefault();
                this.aProducts.sizes          = db.ProductSize.Where(s => s.product == this.aProducts.choosenProduct.id);
                this.aProducts.editedSize     = new ProductSize();
            }
            if (sizeId != 0 && sizeAlter != 0)
            {
                ProductSize sz = db.ProductSize.FirstOrDefault(s => s.id == sizeId);
                db.Entry(sz).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                sz.quantity        = Convert.ToString((int.Parse(sz.quantity) + sizeAlter));
                db.Update(sz);
                db.SaveChanges();
            }

            if (func == "edit")
            {
                this.isCreation = false;
                this.aProducts.editedProduct = db.Product.FirstOrDefault(p => p.id == id);
            }
            else if (func == "delete")
            {
                Product pd = db.Product.FirstOrDefault(p => p.id == id);
                db.Product.Remove(pd);
                db.SaveChanges();
            }
            else
            {
                this.isCreation = true;
                this.aProducts.editedProduct = new Product()
                {
                    id = 0
                };
            }
        }
Example #3
0
        public IActionResult Catalog(String dresses, String leggings, String bloudseAndshirts,
                                     String coatsAndjackets, String hoodiesAndsweats, String denim, String jeans, String jumpersAndcardigans,
                                     string size, int price, string deletion, string subcat, string subsize, int subprice, int cpId, int wpId,
                                     int cart_remove, int wish_remove, int dpId, string sort)
        {
            if (cart_remove != 0)
            {
                //Product cp = db.Product.Where(p => p.id == cart_remove).FirstOrDefault();
                int ind = cart_products.IndexOf(cart_products.Where(p => p.id == cart_remove).FirstOrDefault());
                cart_products.RemoveAt(ind);
                cart_images.RemoveAt(ind);
                cart_items.RemoveAt(ind);
            }
            if (wish_remove != 0)
            {
                //Product cp = db.Product.Where(p => p.id == wish_remove).FirstOrDefault();
                int ind = wish_products.IndexOf(wish_products.Where(p => p.id == wish_remove).FirstOrDefault());
                wish_products.RemoveAt(ind);
                wish_images.RemoveAt(ind);
            }
            if (cpId != 0)
            {
                //Product cp = db.Product.Where(p => p.id == cpId).FirstOrDefault();
                if (!cart_products.Contains(cart_products.Where(p => p.id == cpId).FirstOrDefault()))
                {
                    cart_products.Add(db.Product.Where(p => p.id == cpId).FirstOrDefault());
                    cart_images.Add(db.Image.Where(p => p.whose == (1000 + cpId)).FirstOrDefault());
                    ItemForm iform = new ItemForm()
                    {
                        product  = cpId,
                        price    = Convert.ToInt32(db.Product.Where(p => p.id == cpId).FirstOrDefault().price),
                        quantity = 1,
                        sizes    = db.ProductSize.Where(p => p.product == cpId).ToList(),
                    };
                    cart_items.Add(iform);
                }
            }
            if (wpId != 0)
            {
                //Product wp = db.Product.Where(p => p.id == wpId).FirstOrDefault();
                if (!wish_products.Contains(wish_products.Where(p => p.id == wpId).FirstOrDefault()))
                {
                    wish_products.Add(db.Product.Where(p => p.id == wpId).FirstOrDefault());
                    wish_images.Add(db.Image.Where(p => p.whose == (1000 + wpId)).FirstOrDefault());
                }
            }
            if (dpId != 0)
            {
                if (!detail_products.Contains(detail_products.Where(d => d.id == dpId).FirstOrDefault()))
                {
                    detail_products.Add(db.Product.Where(d => d.id == dpId).FirstOrDefault());
                    detail_images.Add(db.Image.Where(d => d.whose == (1000 + dpId)).FirstOrDefault());
                }
            }


            if (deletion != null && deletion != "")
            {
                if (deletion == "category")
                {
                    //catalog.category = "";
                    //c_cat = true;
                    category_filters.Remove(subcat.ToLower());
                }
                if (deletion == "size")
                {
                    //catalog.size = "";
                    //c_size = true;
                    size_filters.Remove(subsize);
                }
                if (deletion == "price")
                {
                    //catalog.price = 0;
                    //c_price = true;
                    price_filters.Remove(subprice);
                }
            }
            if (price != 0 && !price_filters.Contains(price))
            {
                price_filters.Add(price);
            }
            if (size != null && size != "" && !size_filters.Contains(size))
            {
                size_filters.Add(size);
            }
            if (dresses != null && dresses != "" && !category_filters.Contains(dresses))
            {
                category_filters.Add(dresses);
            }
            List <Product> priced_products = new List <Product>();

            products     = new List <Product>();
            productSizes = new List <ProductSize>();

            if (price_filters == null || price_filters.Count() == 0)
            {
                priced_products = db.Product.ToList();
            }
            else
            {
                foreach (var p in price_filters)
                {
                    if (p == 1)
                    {
                        List <Product> pds = db.Product.Where(s => (Convert.ToInt32(s.price)) >= 10 && (Convert.ToInt32(s.price)) <= 49).ToList();
                        priced_products.AddRange(pds);
                    }
                    else if (p == 2)
                    {
                        List <Product> pds = db.Product.Where(s => (Convert.ToInt32(s.price)) >= 50 && (Convert.ToInt32(s.price)) <= 99).ToList();
                        priced_products.AddRange(pds);
                    }
                    else if (p == 3)
                    {
                        List <Product> pds = db.Product.Where(s => (Convert.ToInt32(s.price)) >= 100 && (Convert.ToInt32(s.price)) <= 199).ToList();
                        priced_products.AddRange(pds);
                    }
                    else if (p == 4)
                    {
                        List <Product> pds = db.Product.Where(s => (Convert.ToInt32(s.price)) >= 200).ToList();
                        priced_products.AddRange(pds);
                    }

                    //catalog.size = size;
                }
            }


            if (size_filters == null || size_filters.Count() == 0)
            {
                productSizes = db.ProductSize.ToList();
            }
            else
            {
                foreach (string s in size_filters)
                {
                    List <ProductSize> sz = db.ProductSize.Where(_s => _s.size == s).ToList();
                    productSizes.AddRange(sz);
                }
            }
            if (category_filters == null || category_filters.Count() == 0)
            {
                products = priced_products;
            }
            else
            {
                foreach (var c in category_filters)
                {
                    List <Product> _category = priced_products.Where(p => p.category.Contains(c.ToLower())).ToList();
                    products.AddRange(_category);
                }
            }


            //

            /*string cat=catalog.category*/
            ;
            //string sz = catalog.size;
            //int pr = catalog.price;
            //if (dresses != null && dresses != "")
            //{
            //    products = products.Where(p => p.category.Contains(dresses)).ToList();
            //    catalog.category = dresses.ToUpper();
            //    category_filters.Add(dresses);

            //}
            if (leggings != null && leggings != "")
            {
                products = products.Where(p => p.category.Contains(leggings)).ToList();
                //catalog.category = dresses.ToUpper();
                //c_cat = true;

                products     = db.Product.ToList();
                productSizes = db.ProductSize.ToList();
            }
            if (bloudseAndshirts != null && bloudseAndshirts != "")
            {
                products = products.Where(p => p.category.Contains(bloudseAndshirts)).ToList();
                //catalog.category = dresses.ToUpper();
                //c_cat = true;
            }
            if (leggings != null && leggings != "")
            {
                products         = products.Where(p => p.category.Contains(leggings)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (coatsAndjackets != null && coatsAndjackets != "")
            {
                products = products.Where(p => p.category.Contains(coatsAndjackets)).ToList();
                //catalog.category = dresses.ToUpper();
                //c_cat = true;
            }
            if (bloudseAndshirts != null && bloudseAndshirts != "")
            {
                products         = products.Where(p => p.category.Contains(bloudseAndshirts)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (hoodiesAndsweats != null && hoodiesAndsweats != "")
            {
                products = products.Where(p => p.category.Contains(hoodiesAndsweats)).ToList();
                //catalog.category = dresses.ToUpper();
                //c_cat = true;
            }
            if (coatsAndjackets != null && coatsAndjackets != "")
            {
                products         = products.Where(p => p.category.Contains(coatsAndjackets)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (denim != null && denim != "")
            {
                products = products.Where(p => p.category.Contains(denim)).ToList();
                //catalog.category = dresses.ToUpper();
                //c_cat = true;
            }
            if (hoodiesAndsweats != null && hoodiesAndsweats != "")
            {
                products         = products.Where(p => p.category.Contains(hoodiesAndsweats)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (denim != null && denim != "")
            {
                products         = products.Where(p => p.category.Contains(denim)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (jumpersAndcardigans != null && jumpersAndcardigans != "")
            {
                products         = products.Where(p => p.category.Contains(jumpersAndcardigans)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }
            if (jeans != null && jeans != "")
            {
                products         = products.Where(p => p.category.Contains(jeans)).ToList();
                catalog.category = dresses.ToUpper();
                c_cat            = true;
            }



            if (price == 1)
            {
                products           = products.Where(p => Convert.ToInt32(p.price) >= 10 && Convert.ToInt32(p.price) <= 49).ToList();
                this.catalog.price = price;
                c_price            = true;
            }
            else if (price == 2)
            {
                products           = products.Where(p => Convert.ToInt32(p.price) >= 50 && Convert.ToInt32(p.price) <= 99).ToList();
                this.catalog.price = price;
                c_price            = true;
            }
            else if (price == 3)
            {
                products           = products.Where(p => Convert.ToInt32(p.price) >= 100 && Convert.ToInt32(p.price) <= 199).ToList();
                this.catalog.price = price;
                c_price            = true;
            }
            else if (price == 4)
            {
                products           = products.Where(p => Convert.ToInt32(p.price) >= 200).ToList();
                this.catalog.price = price;
                c_price            = true;
            }

            if (size == "S" || size == "M" || size == "L" || size == "XL" || size == "2XL" || size == "One Size")
            {
                productSizes      = productSizes.Where(s => s.size == size).ToList();
                this.catalog.size = size;
                c_size            = true;
            }



            initCatalog(products, productSizes, images);
            if (c_price == false)
            {
                this.catalog.price = old_price;
            }
            if (c_size == false)
            {
                this.catalog.size = old_size;
            }
            if (c_cat == false)
            {
                this.catalog.category = old_category;
            }

            if (cart != null && cart != "")
            {
                Product pd = this.catalog.products.Where(p => p.product.id == Convert.ToInt32(cart)).FirstOrDefault().product;

                ////Item cd = new Item()
                ////{
                ////    product = pd.id,
                ////    cart =
                ////};
                //this.catalog.cartProducts.Add(pd);
                //this.catalog.cartTotal +=pd.price;
                Item cp = new Item()
                {
                    products = products.Where(p => p.category.Contains(jumpersAndcardigans)).ToList();
                    //catalog.category = dresses.ToUpper();
                    //c_cat = true;

                    this.catalog.items = db.Item.Where(i => i.cart == 1).ToList();
                    List <int> pIds = new List <int>();

                    foreach (var i in this.catalog.items)
                    {
                        if (!pIds.Contains(i.product))
                        {
                            pIds.Add(i.product);
                        }
                    }
                    this.catalog.cartTotal = 0;
                    foreach (var p in this.catalog.products)
                    {
                        products = products.Where(p => p.category.Contains(jeans)).ToList();
                        //catalog.category = dresses.ToUpper();
                        //c_cat = true;
                    }
                }
            }
            if (cartRemove != null && cartRemove != "")
            {
                Product pd = this.catalog.products.Where(p => p.product.id == Convert.ToInt32(cartRemove)).FirstOrDefault().product;

                ////Item cd = new Item()
                ////{
                ////    product = pd.id,
                ////    cart =
                ////};
                //this.catalog.cartProducts.Add(pd);
                //this.catalog.cartTotal +=pd.price;
                Item cp = db.Item.Where(i => i.product == pd.id).FirstOrDefault();
                db.Item.Remove(cp);
                db.SaveChanges();

                //if (price == 1)
                //{
                //    products = products.Where(p => Convert.ToInt32(p.price) >= 10 && Convert.ToInt32(p.price) <= 49).ToList();
                //    catalog.price = price;
                //    c_price = true;

                //}
                //else if (price == 2)
                //{
                //    products = products.Where(p => Convert.ToInt32(p.price) >= 50 && Convert.ToInt32(p.price) <= 99).ToList();
                //    catalog.price = price;
                //    c_price = true;

                //}
                //else if (price == 3)
                //{
                //    products = products.Where(p => Convert.ToInt32(p.price) >= 100 && Convert.ToInt32(p.price) <= 199).ToList();
                //    catalog.price = price;
                //    c_price = true;

                //}
                //else if (price == 4)
                //{
                //    products = products.Where(p => Convert.ToInt32(p.price) >= 200).ToList();
                //    catalog.price = price;
                //    c_price = true;

                //}

                //if (size == "S" || size == "M" || size == "L" || size == "XL" || size == "2XL" || size == "One Size")
                //{
                //    productSizes = productSizes.Where(s => s.size == size).ToList();
                //    catalog.size = size;
                //    c_size = true;

                //}



                initCatalog(products, productSizes, images);
                catalog.price_filters    = price_filters;
                catalog.size_filters     = size_filters;
                catalog.category_filters = category_filters;
                catalog.cart_product     = cart_products;
                catalog.wish_product     = wish_products;
                catalog.wish_images      = wish_images;
                catalog.cart_images      = cart_images;
                catalog.detail_images    = detail_images;
                catalog.detail_product   = detail_products;
                catalog.items            = cart_items;


                //if (c_price == false)
                //{
                //    catalog.price = old_price;
                //}
                //if (c_size == false)
                //{
                //    catalog.size = old_size;
                //}
                //if (c_cat == false)
                //{
                //    catalog.category = old_category;
                //}
                return(View(catalog));
            }