Пример #1
0
        public static string AppendFileSuffix(string fileName, ProductSizes sizes)
        {
            string suffix         = string.Empty;
            string fixed_size_str = "_{0}_{1}";

            switch (sizes)
            {
            case ProductSizes.Size100:
                suffix = string.Format(fixed_size_str, 100, 100);
                break;

            case ProductSizes.Size300:
                suffix = string.Format(fixed_size_str, 300, 300);
                break;

            case ProductSizes.Size640:
                suffix = string.Format(fixed_size_str, 640, 640);
                break;

            default:
                suffix = string.Empty;
                break;
            }

            return(AppendFileSuffix(fileName, suffix));
        }
        public void AddToCart(Product product, ProductSizes size, int count)
        {
            // Get the matching cart and album instances
            var cartItem = context.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                c.ProductId == product.Id && c.ProductSizeId == size.Id);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    ProductId     = product.Id,
                    ProductSizeId = size.Id,
                    CartId        = ShoppingCartId,
                    Count         = count,
                    DateCreated   = DateTime.Now
                };
                context.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count += count;
            }
            // Save changes
            context.SaveChanges();
        }
Пример #3
0
        public void CreateSizes(int ProductId, string SizeId)
        {
            int sz = 0;

            Int32.TryParse(SizeId, out sz);

            var product = _context.Products.Include(p => p.AvalableSizes).FirstOrDefault(p => p.Id == ProductId);
            //product.AvalableSizes = _context.ProductSizes.Where(pr => pr.ProductId == ProductId).ToList();
            var size = _context.Sizes.FirstOrDefault(s => s.Id == sz);

            //if (_context.ProductSizes.Any(pr => pr.ProductId == ProductId & pr.SizeId == sz))
            //{
            //    // do nothing
            //    NotFound();
            //    return;
            //}

            var ps = new ProductSizes
            {
                ProductId = product.Id,
                SizeId    = size.Id
            };

            product.AvalableSizes.Add(ps);
            _context.SaveChanges();
        }
Пример #4
0
        private void LoadProductSize()
        {
            var list = ProductSizes.List();

            cbxProductSizes.DataSource    = list;
            cbxProductSizes.DisplayMember = "Name";
        }
Пример #5
0
        public ActionResult Create(ProductSizes productSizes)
        {
            if (ModelState.IsValid)
            {
                Handler.AddProductSize(productSizes);

                List <ProductSizes> list = Handler.GetProductByName(Handler.GetProductById(productSizes.ProductId).Name);
                int quantity             = 0;
                foreach (ProductSizes item in list)
                {
                    quantity += item.Quantity;
                }

                Handler.AddStock(new Stock()
                {
                    ProductId = productSizes.ProductId,
                    Quantity  = quantity
                });

                return(RedirectToAction("Index", "ProductSize"));
            }
            ViewBag.SizeId    = new SelectList(Context.Categories, "Id", "Name", productSizes.SizeId);
            ViewBag.ProductId = new SelectList(Context.Categories, "Id", "Name", productSizes.ProductId);
            return(View(productSizes));
        }
Пример #6
0
 public void UpdateProductSize(ProductSizes entity)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #7
0
 public void DeleteProductSize(int?id)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         ProductSizes found = context.ProductSizes.FirstOrDefault(p => p.Id == id);
         context.ProductSizes.Remove(found);
         context.SaveChanges();
     }
 }
Пример #8
0
/// <summary>
/// Update ProductSize
/// </summary>
/// <param name="entity"></param>
/// <returns>Message</returns>
        public async Task <string> UpdateProductSize(ProductSizes entity)
        {
            try
            {
                var result = await new ProductSizeRepository(logger).Update(entity);
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
        }
Пример #9
0
        public ActionResult Edit(ProductSizes productSizes)
        {
            if (ModelState.IsValid)
            {
                Handler.UpdateProductSize(productSizes);
                return(RedirectToAction("Index", "ProductSize"));
            }

            ViewBag.SizeId    = new SelectList(Context.Categories, "Id", "Name", productSizes.SizeId);
            ViewBag.ProductId = new SelectList(Context.Categories, "Id", "Name", productSizes.ProductId);

            return(View(productSizes));
        }
        public async Task <ActionResult> Edit(ProductSizes data)
        {
            string result = string.Empty;

            try
            {
                result = await repo.UpdateProductSize(data);
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #11
0
        public ActionResult Delete(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProductSizes productSize = Handler.GetProductSize(Id);

            if (productSize == null)
            {
                return(HttpNotFound());
            }
            return(View(productSize));
        }
        public async Task <JsonResult> Delete(string ids)
        {
            string result = string.Empty;

            string[]     IdList = ids.Split('~');
            ProductSizes vm     = new ProductSizes();

            try
            {
                result = await repo.IsDeleteProductSize(IdList, vm);
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #13
0
/// <summary>
/// Delete ProductSize
/// </summary>
/// <param name="Id"></param>
/// <returns>Message</returns>
        public async Task <string> IsDeleteProductSize(string[] IdList, ProductSizes entity)
        {
            string result = string.Empty;

            try
            {
                for (int i = 0; i < IdList.Length - 1; i++)
                {
                    result = await new ProductSizeRepository(logger).IsDelete(Convert.ToInt32(IdList[i]), entity);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw ex;
            }
            return(result);
        }
Пример #14
0
        public ActionResult Edit(int?Id)
        {
            ViewBag.SizeId    = new SelectList(Context.Sizes, "Id", "Name");
            ViewBag.ProductId = new SelectList(Context.Products, "Id", "Name");

            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProductSizes productSize = Handler.GetProductSize(Id);

            if (productSize == null)
            {
                return(HttpNotFound());
            }
            return(View(productSize));
        }
Пример #15
0
        public void AddProductSize(ProductSizes entity)
        {
            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                ProductSizes temp = context.ProductSizes
                                    .Where(p => p.ProductId == entity.ProductId && p.SizeId == entity.SizeId)
                                    .SingleOrDefault();

                if (temp != null)
                {
                    temp.Quantity             = temp.Quantity + entity.Quantity;
                    context.Entry(temp).State = EntityState.Modified;
                }
                else
                {
                    context.Entry(entity).State = EntityState.Added;
                }

                context.SaveChanges();
            }
        }
Пример #16
0
        //
        // GET: /Store/AddToCart/5
        public ActionResult AddToCart(CartModel model)
        {
            context.Configuration.ProxyCreationEnabled = false;
            if (model.Count < 1)
            {
                model.Count++;
            }
            // Retrieve the product from the database
            Product selectedProduct = context.Products
                                      .Single(p => p.Id == model.Id);

            // Retrieve the productsize from the database
            ProductSizes selectedSize = context.ProductSizes
                                        .Single(p => p.Id == model.size_id && p.ProductId == model.Id);

            // Add it to the shopping cart
            ShoppingCart cart = ShoppingCart.GetCart(HttpContext);

            cart.AddToCart(selectedProduct, selectedSize, model.Count);

            // Go back to the main store page for more shopping
            return(Json(new { Result = "Success", Message = "Save successfully" }, JsonRequestBehavior.AllowGet));
        }
Пример #17
0
 public Golfer(string name, ProductSizes size) : base(name, size)
 {
 }
Пример #18
0
 protected Pants(string name, ProductSizes size)
 {
     Name = name;
     Size = size;
 }
Пример #19
0
        public async Task <IActionResult> Create(ProColors colors)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                ViewBag.Active = "Home";
                ViewBag.Color  = _context.Colors;
                ViewBag.Brand  = _context.Brands.Where(b => b.Id == colors.BrandsId);
                ViewBag.Size   = _context.Sizes;
                return(View(colors));
            }

            if (colors.AllPhotos == null)
            {
                ViewBag.Active = "Home";
                ViewBag.Color  = _context.Colors;
                ViewBag.Size   = _context.Sizes;
                ViewBag.Brand  = _context.Brands.Where(b => b.Id == colors.BrandsId);

                ModelState.AddModelError("AllPhotos", "Xahiş olunur şəkil əlavə edin.");

                return(View(colors));
            }

            Products myProduct = new Products()
            {
                Name     = colors.Name,
                Info     = colors.Info,
                Price    = colors.Price,
                BrandsId = colors.BrandsId
            };

            await _context.Products.AddAsync(myProduct);

            bool isMain = true;

            foreach (var p in colors.AllPhotos)
            {
                if (p != null)
                {
                    if (p.ContentType.Contains("image/"))
                    {
                        string filename = await p.SaveAsync(_env.WebRootPath);

                        ProductPhoto img = new ProductPhoto()
                        {
                            ProductsId = myProduct.Id,
                            PhotoURL   = filename
                        };

                        if (isMain == true)
                        {
                            img.IsMain = true;
                        }
                        isMain = false;

                        await _context.ProductPhoto.AddAsync(img);
                    }
                }
            }
            foreach (var c in colors.ColorsId)
            {
                ProductColors proColors = new ProductColors()
                {
                    ProductsId = myProduct.Id,
                    ColorId    = c
                };

                await _context.ProductColors.AddAsync(proColors);
            }
            foreach (var s in colors.SizesId)
            {
                ProductSizes proSize = new ProductSizes()
                {
                    ProductsId = myProduct.Id,
                    SizesId    = s
                };
                await _context.ProductSizes.AddAsync(proSize);
            }

            Brands brand = await _context.Brands.FindAsync(myProduct.BrandsId);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", new { id = brand.Id }));
        }
Пример #20
0
 public Jeans(string name, ProductSizes size) : base(name, size)
 {
 }
Пример #21
0
 public FormalPants(string name, ProductSizes size) : base(name, size)
 {
 }
Пример #22
0
 protected Shirt(string name, ProductSizes size)
 {
     Name = name;
     Size = size;
 }
Пример #23
0
 public TShirt(string name, ProductSizes size) : base(name, size)
 {
 }
Пример #24
0
        public async Task <IActionResult> EditPost(ProColors color)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                ViewBag.Color = _context.Colors;
                ViewBag.Size  = _context.Sizes;

                ModelState.AddModelError("", "Xaiş olunur düzgün doldurun.");
                return(View(color));
            }

            Products newProduct = await _context.Products.FindAsync(color.Id);

            Brands brand = await _context.Brands.FindAsync(newProduct.BrandsId);

            if (newProduct == null)
            {
                return(View("Error"));
            }

            if (color.AllPhotos != null)
            {
                IEnumerable <ProductPhoto> myPhoto = newProduct.Photos.Where(b => b.ProductsId == newProduct.Id);


                foreach (var photo in myPhoto)
                {
                    string computerPhoto = Path.Combine(_env.WebRootPath, "img", photo.PhotoURL);

                    if (System.IO.File.Exists(computerPhoto))
                    {
                        System.IO.File.Delete(computerPhoto);
                    }

                    _context.RemoveRange(myPhoto);
                }

                bool isMain = true;

                foreach (var p in color.AllPhotos)
                {
                    if (p != null)
                    {
                        if (p.ContentType.Contains("image/"))
                        {
                            string filename = await p.SaveAsync(_env.WebRootPath);

                            ProductPhoto img = new ProductPhoto()
                            {
                                ProductsId = newProduct.Id,
                                PhotoURL   = filename
                            };

                            if (isMain == true)
                            {
                                img.IsMain = true;
                            }
                            isMain = false;

                            await _context.ProductPhoto.AddAsync(img);
                        }
                    }
                }
            }

            newProduct.Name  = color.Name;
            newProduct.Info  = color.Info;
            newProduct.Price = color.Price;

            IEnumerable <ProductColors> oldColors = _context.ProductColors.Where(p => p.ProductsId == newProduct.Id);
            IEnumerable <ProductSizes>  oldSizes  = _context.ProductSizes.Where(p => p.ProductsId == newProduct.Id);

            if (color.ColorsId != null)
            {
                _context.ProductColors.RemoveRange(oldColors);

                foreach (var c in color.ColorsId)
                {
                    ProductColors proColors = new ProductColors()
                    {
                        ProductsId = newProduct.Id,
                        ColorId    = c
                    };

                    await _context.ProductColors.AddAsync(proColors);
                }
            }
            if (color.SizesId != null)
            {
                _context.ProductSizes.RemoveRange(oldSizes);

                foreach (var s in color.SizesId)
                {
                    ProductSizes proSize = new ProductSizes()
                    {
                        ProductsId = newProduct.Id,
                        SizesId    = s
                    };

                    await _context.ProductSizes.AddAsync(proSize);
                }
            }


            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", new { id = brand.Id }));
        }