public async Task <IActionResult> DeleteImage(long Id) { var _image = await _imageRepository.GetSingleAsync(x => x.Id == Id); if (_image == null) { return(new NotFoundResult()); } var url = _image.ImageUrl; _imageRepository.Delete(_image); await _imageRepository.Commit(); Uri u = new Uri(url); var path = u.LocalPath.Replace("/", "\\"); var localPath = string.Format("{0}{1}", _environment.WebRootPath, path); FileInfo file = new FileInfo(localPath); await Task.Factory.StartNew(() => file.Delete()); return(new NoContentResult()); }