public async Task <IActionResult> Delete(Guid id) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); User myUser = _repository.GetUser(user.Id); List <Photo> photosToDelete = await _repository.GetPhotosAsync(id); List <string> paths = new List <string>(); foreach (Photo photoToDelete in photosToDelete) { string[] parts = photoToDelete.URL.Split('/'); string filename = Path.Combine(_environment.WebRootPath, "uploads") + $@"\{parts[2]}";; paths.Add(filename); filename = Path.Combine(_environment.WebRootPath, "uploads") + $@"\thumbs" + $@"\{parts[2]}"; paths.Add(filename); } try { foreach (String path in paths) { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } } catch (IOException ex) { return(View("AlbumError")); } await _repository.RemoveMyAlbumAsync(myUser, id); return(RedirectToAction("Index")); }