public ActionResult StoreFile(CreateResearchFileRequest req) { string path = Path.Combine(_env.WebRootPath, "files"); IList <ResearchFile> researchFiles = new List <ResearchFile>(); Project project = _context.Project.Where(proj => proj.Uid == req.uid).First <Project>(); if (req.Files != null) { foreach (IFormFile file in req.Files) { string fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); string filepath = Path.Combine(path, fileName); FileStream fileStream = new FileStream(filepath, FileMode.Create); file.CopyTo(fileStream); fileStream.Close(); AzureFileService fileService = new AzureFileService(this._appSettings); fileService.storeFile("files", fileName, filepath); ResearchFile researchFile = new ResearchFile(); researchFile.FileName = fileName; researchFile.ProjectId = project.Id; researchFiles.Add(researchFile); _context.ResearchFile.Add(researchFile); } } _context.SaveChanges(); return(Ok(researchFiles)); }
public ActionResult DeleteFile(DeleteFileRequest req) { AzureFileService fileService = new AzureFileService(this._appSettings); var result = fileService.DeleteFile("files", req.FileName); if (result) { ResearchFile research = _context.ResearchFile.Where( researchFile => researchFile.ProjectId == req.ProjectId && researchFile.FileName == req.FileName).FirstOrDefault(); _context.ResearchFile.Remove(research); IList <ResearchFile> researchFileList = _context.ResearchFile.Where( researchFile => researchFile.ProjectId == req.ProjectId).ToList(); return(Ok(researchFileList)); } return(NotFound()); }