// POST: api/Share public async Task Post() { HttpContext httpContext = HttpContext.Current; SharedVulnerability sharedVulnerability = new SharedVulnerability(); sharedVulnerability.Comment = httpContext.Request.Form["Comment"]; sharedVulnerability.CommitMessage = httpContext.Request.Form["CommitMessage"]; sharedVulnerability.CweId = int.TryParse(httpContext.Request.Form["CweId"], out int cweId) ? cweId : (int?)null; foreach (string key in httpContext.Request.Files.AllKeys) { SharedFile sharedFile = new SharedFile(); HttpPostedFile file = httpContext.Request.Files[key]; sharedFile.Name = file.FileName; using (BinaryReader binaryReader = new BinaryReader(file.InputStream)) { sharedFile.Content = binaryReader.ReadBytes(file.ContentLength); } sharedFile.VulnerabilityState = key.StartsWith("currentFile") ? VulnerabilityState.AfterFix : VulnerabilityState.Vulnerable; sharedVulnerability.SharedFiles.Add(sharedFile); } micscanContext.SharedVulnerabilities.Add(sharedVulnerability); await micscanContext.SaveChangesAsync(); }
public async Task Post() { HttpContext httpContext = HttpContext.Current; SharedVulnerability sharedVulnerability = new SharedVulnerability(); sharedVulnerability.Comment = httpContext.Request.Form["Comment"]; sharedVulnerability.CommitMessage = httpContext.Request.Form["CommitMessage"]; sharedVulnerability.CweId = int.TryParse(httpContext.Request.Form["CweId"], out int cweId) ? cweId : (int?)null; bool fixedWithCommit = bool.Parse(httpContext.Request.Form["FixedWithCommit"]); foreach (string key in httpContext.Request.Files.AllKeys) { int fileId = ParseFileId(key); SharedFile sharedFile = new SharedFile(); HttpPostedFile file = httpContext.Request.Files[key]; sharedFile.Name = file.FileName; int changeKind = int.Parse(httpContext.Request.Form[$"File{fileId}ChangeKind"]); sharedFile.ChangeKind = (ChangeKind)changeKind; using (BinaryReader binaryReader = new BinaryReader(file.InputStream)) { sharedFile.Content = binaryReader.ReadBytes(file.ContentLength); } if (fixedWithCommit) { sharedFile.VulnerabilityState = key.StartsWith("CurrentFile") ? VulnerabilityState.AfterFix : VulnerabilityState.Vulnerable; } else { sharedFile.VulnerabilityState = key.StartsWith("CurrentFile") ? VulnerabilityState.Vulnerable : VulnerabilityState.BeforeIntroduction; } sharedVulnerability.SharedFiles.Add(sharedFile); } micscanContext.SharedVulnerabilities.Add(sharedVulnerability); await micscanContext.SaveChangesAsync(); }