public void Destroy(int id) { Models.File file = _db.Files.Find(id); File.Delete(file.Path); Directory.Delete(new FileInfo(file.Path).DirectoryName); _db.Files.Remove(file); _db.SaveChanges(); }
public void Save(IFormFile uploadedFile, int hours, int userId) { if (uploadedFile == null) { return; } string folder = $"{_appEnvironment.WebRootPath}{_path}{DateTime.UtcNow.ToFileTimeUtc().ToString()}"; Directory.CreateDirectory(folder); string path = $"{folder}/{uploadedFile.FileName}"; Models.File file = new Models.File(path, hours, userId); _db.Files.Add(file); _db.SaveChanges(); FileStream fs = new FileStream(path, FileMode.Create); uploadedFile.CopyTo(fs); fs.Close(); }