public IActionResult Create()
        {
            ProductCrudVM productCrud = new ProductCrudVM()
            {
                ProductCategories = _db.ProductCategories.ToList()
            };

            return(View(productCrud));
        }
Exemplo n.º 2
0
        public IActionResult Create()
        {
            ProductCrudVM product = new ProductCrudVM()
            {
                Products = _db.Products.ToList(),
            };

            return(View(product));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(ProductCrudVM productCrud)
        {
            ProductImage productImage = new ProductImage()
            {
                Name = productCrud.Name
            };

            if (productCrud.Photo == null)
            {
                ModelState.AddModelError("", "Shekil sechin");
                ProductCrudVM products = new ProductCrudVM()
                {
                    Products = _db.Products.ToList(),
                };
                return(View(products));
            }
            if (!productCrud.Photo.IsImage())
            {
                ModelState.AddModelError("", "Shekil formatinda bir fayl sechin");
                ProductCrudVM products = new ProductCrudVM()
                {
                    Products = _db.Products.ToList(),
                };
                return(View(products));
            }
            if (productCrud.Photo.MaxLength(1400))
            {
                ModelState.AddModelError("", "Shekilin olchusu max 1400kb ola biler");
                ProductCrudVM products = new ProductCrudVM()
                {
                    Products = _db.Products.ToList(),
                };
                return(View(products));
            }
            productImage.Image = await productCrud.Photo.SaveImage(_env.WebRootPath, "img/shop");

            string  aaaa    = Request.Form["product"];
            Product product = _db.Products.FirstOrDefault(s => s.Name.ToLower().Trim() == aaaa.ToLower().Trim());

            productImage.ProductId = product.Id;
            string b = Request.Form["ismain"];

            if (b.ToLower().Trim() == "main")
            {
                productImage.IsMain = true;
            }
            else
            {
                productImage.IsMain = false;
            }
            _db.ProductImages.Add(productImage);
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ProductCrudVM productCrud = new ProductCrudVM
            {
                ProductImage = _db.ProductImages.Find(id),
                Products     = _db.Products.ToList()
            };

            if (productCrud == null)
            {
                return(NotFound());
            }
            return(View(productCrud));
        }
        public async Task <IActionResult> Create(ProductCrudVM product)
        {
            Product product1 = new Product()
            {
                About = product.About,
                Count = product.Count,
                Name  = product.Name,
                Price = product.Price
            };
            string          a        = Request.Form["categories"];
            ProductCategory category = _db.ProductCategories.FirstOrDefault(p => p.Name.ToLower().Trim() == a.ToLower().Trim());

            product1.ProductCategoryId = category.Id;
            await _db.AddAsync(product1);

            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Product       p           = _db.Products.Include(a => a.ProductCategory).FirstOrDefault(a => a.Id == id);
            ProductCrudVM productCrud = new ProductCrudVM()
            {
                ProductCategories = _db.ProductCategories.ToList(),
                Name    = p.Name,
                Price   = p.Price,
                Count   = p.Count,
                About   = p.About,
                Product = p
            };

            if (productCrud == null)
            {
                return(NotFound());
            }
            return(View(productCrud));
        }
        public async Task <IActionResult> Edit(int?id, ProductCrudVM productt)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Product product = _db.Products.Find(id);

            if (product == null)
            {
                return(NotFound());
            }
            product.About = productt.About;
            product.Count = productt.Count;
            product.Name  = productt.Name;
            product.Price = productt.Price;
            string          a        = Request.Form["categories"];
            ProductCategory category = _db.ProductCategories.FirstOrDefault(p => p.Name.ToLower().Trim() == a.ToLower().Trim());

            product.ProductCategoryId = category.Id;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int?id, ProductCrudVM productImage)
        {
            if (id == null)
            {
                return(View());
            }
            ProductImage productImage1 = _db.ProductImages.Find(id);

            if (productImage1 == null)
            {
                return(NotFound());
            }
            if (productImage.Photo != null)
            {
                if (!productImage.Photo.IsImage())
                {
                    ModelState.AddModelError("", "Shekil formatinda bir fayl sechin");
                    return(View());
                }
                if (productImage.Photo.MaxLength(1400))
                {
                    ModelState.AddModelError("", "Shekilin olchusu max 1400kb ola biler");
                    return(View());
                }
                Helper.DeleteImg(_env.WebRootPath, "img/shop", productImage1.Image);
                productImage1.Image = await productImage.Photo.SaveImage(_env.WebRootPath, "img/shop");

                string  aaaa    = Request.Form["product"];
                Product product = _db.Products.FirstOrDefault(s => s.Name.ToLower().Trim() == aaaa.ToLower().Trim());
                productImage1.ProductId = product.Id;
                string b = Request.Form["ismain"];
                if (b.ToLower().Trim() == "main")
                {
                    productImage1.IsMain = true;
                }
                else
                {
                    productImage1.IsMain = false;
                }
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                string  aaaa    = Request.Form["product"];
                Product product = _db.Products.FirstOrDefault(s => s.Name.ToLower().Trim() == aaaa.ToLower().Trim());
                productImage1.ProductId = product.Id;
                string b = Request.Form["ismain"];
                if (b.ToLower().Trim() == "main")
                {
                    productImage1.IsMain = true;
                }
                else
                {
                    productImage1.IsMain = false;
                }
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }