public async Task <IActionResult> DeleteConfirmed(int id) { var webRoot = _hostingEnvironment.WebRootPath; Products p = null; if (orm == 1) { p = qdb.retProduct(id); } else { p = await _db.Products.FindAsync(id); } if (p == null) { return(NotFound()); } else { var path = Path.Combine(webRoot, SD.ImageFolder); var path2 = Path.Combine(path, p.Id.ToString()) + Path.GetExtension(p.Image); if (System.IO.File.Exists(path2)) { System.IO.File.Delete(path2); } if (orm == 1) { qdb.rmproduct(id); } else { _db.Remove(p); await _db.SaveChangesAsync(); } TempData["delete"] = 1; return(RedirectToAction(nameof(Index))); } }