public async Task <IActionResult> DeleteProductPOST(int id) { var product = await _colibriDbContext.Products.SingleOrDefaultAsync(m => m.Id == id); // Delete Image from DB string webRootPath = _hostingEnvironment.WebRootPath; var uploads = Path.Combine(webRootPath, "img/ProductImage/"); var extension_Old = product.Image.Substring(product.Image.LastIndexOf("."), product.Image.Length - product.Image.LastIndexOf(".")); // delete Image try { System.IO.File.Delete(Path.Combine(uploads, AdvertisementViewModel.Product.Id + extension_Old)); } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); } // Remove product from DB _colibriDbContext.Remove(product); // Save Changes await _colibriDbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeletePOST(int id) { var entry = await _colibriDbContext.ArchiveEntry.SingleOrDefaultAsync(m => m.Id == id); // remove entry from archive _colibriDbContext.Remove(entry); // save changes await _colibriDbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeletePOST() { // Suchanfragen von DB löschen var entries = _colibriDbContext.SearchEntry.ToList(); foreach (var x in entries) { _colibriDbContext.Remove(x); } await _colibriDbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }