Esempio n. 1
0
 public async Task <IActionResult> Edit(IFormFile file, Discountend discountet)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (file != null)
             {
                 if (discountet.ImageCod != null && discountet.ImageCod != string.Empty)
                 {
                     ImagesHelpers.DeleteImage(discountet.ImageCod, "img/discountet/");
                 }
                 discountet.ImageCod = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "discountet");
             }
             _context.Update(discountet);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!DiscountetExists(discountet.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(discountet));
 }
Esempio n. 2
0
 public async Task <IActionResult> Edit(IFormFile file, Slider slider)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (file != null)
             {
                 if (slider.ImageCode != null && slider.ImageCode != string.Empty)
                 {
                     ImagesHelpers.DeleteImage(slider.ImageCode, "img/slider/");
                 }
                 slider.ImageCode = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "slider");
             }
             _context.Update(slider);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!SliderExists(slider.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(slider));
 }
        public async Task <IActionResult> Edit(IFormFile file, int id, Category cate)
        {
            if (id != cate.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(cate));
            }
            if (file != null)
            {
                if (cate.ImageCode != null && cate.ImageCode != string.Empty)
                {
                    ImagesHelpers.DeleteImage(cate.ImageCode, "img/category/");
                }
                cate.ImageCode = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "category");
            }
            _context.Update(cate);
            await _context.SaveChangesAsync();

            var ProCategory = await _context.Categories.FindAsync(id);

            ProCategory.Name = cate.Name;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(IFormFile file, int id, About about)
        {
            if (id != about.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(about));
            }
            if (file != null)
            {
                if (about.ImageCode != null && about.ImageCode != string.Empty)
                {
                    ImagesHelpers.DeleteImage(about.ImageCode, "img/about/");
                }
                about.ImageCode = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "about");
            }
            _context.Update(about);
            await _context.SaveChangesAsync();

            var ProAbout = await _context.Abouts.FindAsync(id);

            ProAbout.Title = about.Title;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 5
0
        // Discountet Edit Function End

        // Discountet Delete Function Start
        public async Task <IActionResult> Delete(int id)
        {
            var discountet = await _context.Discountends.FindAsync(id);

            if (discountet.ImageCod != null && discountet.ImageCod != string.Empty)
            {
                ImagesHelpers.DeleteImage(discountet.ImageCod, "img/discountet/");
            }
            _context.Discountends.Remove(discountet);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 6
0
        //Slider Edit Function End

        //Slider Delete Function Start
        public async Task <IActionResult> Delete(int id)
        {
            var slider = await _context.Sliders.FindAsync(id);

            if (slider.ImageCode != null && slider.ImageCode != string.Empty)
            {
                ImagesHelpers.DeleteImage(slider.ImageCode, "img/slider/");
            }
            _context.Sliders.Remove(slider);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create(IFormFile file, Discountend discountet)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    discountet.ImageCod = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "discountet");
                }
                _context.Add(discountet);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(discountet));
        }
        public async Task <IActionResult> Create(IFormFile file, Category cate)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    cate.ImageCode = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "category");
                }

                var result = await _context.Categories.AddAsync(cate);

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create(IFormFile file, Slider slider)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    slider.ImageCode = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "slider");
                }
                _context.Add(slider);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(slider));
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(ViewModel viewModel, List <IFormFile> file)
        {
            if (ModelState.IsValid)
            {
                Product product = await _context.Products.FindAsync(viewModel.Product.Id);

                if (file.Count != 0)
                {
                    List <ProductImage> images = await _context.ProductImages.Where(i => i.ProductId == viewModel.Product.Id).ToListAsync();

                    foreach (var item in images)
                    {
                        if (item.ImageCode != null && item.ImageCode != string.Empty)
                        {
                            ImagesHelpers.DeleteImage(item.ImageCode, "img/product/");
                        }
                    }
                    _context.ProductImages.RemoveRange(images);
                }

                foreach (var item in file)
                {
                    var image = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, item, "img", "product");

                    await _context.ProductImages.AddAsync(new ProductImage
                    {
                        ProductId = viewModel.Product.Id,
                        ImageCode = image
                    });

                    await _context.SaveChangesAsync();
                }
                {
                    product.Name          = viewModel.Product.Name;
                    product.Description   = viewModel.Product.Description;
                    product.CategoryId    = viewModel.Category.Id;
                    product.Color         = viewModel.ProductColor;
                    product.Size          = viewModel.ProductSize;
                    product.DiscountPrice = viewModel.Product.DiscountPrice;
                    product.Price         = viewModel.Product.Price;

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(viewModel));
        }
Esempio n. 11
0
        public async Task <IActionResult> Edit(ViewModel viewModel, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                Blog blog = await _context.Blogs.FindAsync(viewModel.Blog.Id);

                if (file != null)
                {
                    List <BlogImage> images = await _context.BlogImages.Where(i => i.BlogId == viewModel.Blog.Id).ToListAsync();

                    foreach (var item in images)
                    {
                        if (item.ImageCode != null && item.ImageCode != string.Empty)
                        {
                            ImagesHelpers.DeleteImage(item.ImageCode, "img/blog/");
                        }
                    }
                    _context.BlogImages.RemoveRange(images);
                }


                var image = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "blog");

                await _context.BlogImages.AddAsync(new BlogImage
                {
                    BlogId    = viewModel.Blog.Id,
                    ImageCode = image
                });

                await _context.SaveChangesAsync();

                {
                    blog.Title       = viewModel.Blog.Title;
                    blog.Description = viewModel.Blog.Description;
                    blog.DateTime    = viewModel.Blog.DateTime;
                    blog.UserName    = viewModel.Blog.UserName;

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(viewModel));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create(ViewModel viewModel, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                var Catagory = await _context.Categories.FindAsync(viewModel.Category.Id);

                Product model = new Product()
                {
                    Name          = viewModel.Product.Name,
                    Description   = viewModel.Product.Description,
                    CategoryId    = Catagory.Id,
                    Color         = viewModel.ProductColor,
                    Size          = viewModel.ProductSize,
                    DiscountPrice = viewModel.Product.DiscountPrice,
                    Price         = viewModel.Product.Price,
                };

                await _context.Products.AddAsync(model);

                await _context.SaveChangesAsync();

                int count = 0;
                foreach (var item in files)
                {
                    var image = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, item, "img", "product");

                    await _context.ProductImages.AddAsync(new ProductImage
                    {
                        ProductId = model.Id,
                        ImageCode = image
                    });

                    if (count < files.Count())
                    {
                        model.ProductImages[count].ImageCode = image;
                        ++count;
                    }

                    await _context.SaveChangesAsync();
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 13
0
        // Blog Edit Function End

        // Blog Function Start
        public async Task <IActionResult> Delete(int id)
        {
            var ProBlog = await _context.Blogs.FindAsync(id);

            List <BlogImage> images = _context.BlogImages.Where(i => i.BlogId == ProBlog.Id).ToList();

            foreach (var item in images)
            {
                if (item.ImageCode != null && item.ImageCode != string.Empty)
                {
                    ImagesHelpers.DeleteImage(item.ImageCode, "img/blog/");
                }
            }
            _context.BlogImages.RemoveRange(images);
            await _context.SaveChangesAsync();

            _context.Blogs.Remove(ProBlog);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create(Blog blog, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var ProBlog = await _context.Blogs.AddAsync(blog);

                await _context.SaveChangesAsync();

                if (file != null)
                {
                    var image = await ImagesHelpers.ImageUploadAsync(_env.WebRootPath, file, "img", "blog");

                    await _context.BlogImages.AddAsync(new BlogImage
                    {
                        BlogId    = blog.Id,
                        ImageCode = image
                    });
                }

                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }