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))); }
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)); }
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, 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)); }
// 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))); }
//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))); }
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)); }
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)); }
// 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))); }