public ActionResult UploadPrototype([FromForm] CreatePrototypeRequest req) { Project proj = _context.Project.Where(p => p.Uid == req.ProjectUid).FirstOrDefault <Project>(); string path = Path.Combine(_env.WebRootPath, "files"); IList <string> filePaths = new List <string>(); 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); filePaths.Add(fileName); } } Project Project = _context.Project.Where(project => project.Uid == req.ProjectId).First <Project>(); Prototype prototype = new Prototype(); prototype.ProjectId = Project.Id; prototype.PrototypeName = req.PrototypeName; prototype.PrototypeDescription = req.PrototypeDescription; prototype.Uid = Guid.NewGuid().ToString(); prototype.PrototypePath = Newtonsoft.Json.JsonConvert.SerializeObject(filePaths); var result = _context.Prototype.Add(prototype); _context.SaveChanges(); return(Ok(prototype)); }
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)); }