public bool CheckExistingTracking(int cveID) { // Get existingTrackedCve try { TrackedCve existingTrackedCve = _context.TrackedCves .Where(tc => tc.AspNetUserID == _userManager.GetUserId(User) && tc.CveID == cveID) .FirstOrDefault(); // If it exists return true otherwise false if (existingTrackedCve != null) { return(true); } else { return(false); } } catch (Exception) { throw; } }
public IActionResult Details(int cveID) { string userID = _userManager.GetUserId(User); if (userID == null || cveID == 0) { return(NotFound()); } try { TrackedCve existingTrackedCve = _context.TrackedCves .Where(etc => etc.AspNetUserID == userID && etc.CveID == cveID) .Include(etc => etc.Cve) .ThenInclude(c => c.CveConfigurations) .ThenInclude(etc => etc.Product) .Include(etc => etc.Cve) .ThenInclude(c => c.References) .FirstOrDefault(); return(View(existingTrackedCve)); } catch (Exception) { return(NotFound()); } }
public StatusCodeResult UpdateTrackedVulnerability(string notes, int cveId) { // Check for nulls and 0's if (notes == null || cveId == 0) { return(NotFound()); } // get the existingTrackedCve try { TrackedCve existingTrackedCve = _context.TrackedCves .Where(etc => etc.AspNetUserID == _userManager.GetUserId(User) && etc.CveID == cveId) .FirstOrDefault(); // return if null if (existingTrackedCve == null) { return(NotFound()); } // If notes have changed apply the changes if (existingTrackedCve.Notes != notes) { existingTrackedCve.Notes = notes; _context.TrackedCves.Update(existingTrackedCve); _context.SaveChanges(); return(Ok()); } else { return(Ok()); } } catch (Exception) { return(NotFound()); } }
public IActionResult ChangeVulnerabilityTracking(int cveID) { string aspNetUserID = _userManager.GetUserId(User); // Get existingTrackedCve if it exists var existingTrackedCve = _context.TrackedCves .Where(tc => tc.AspNetUserID == aspNetUserID && tc.CveID == cveID) .FirstOrDefault(); // It it does exist, remove it if (existingTrackedCve != null) { try { _context.TrackedCves.Remove(existingTrackedCve); _context.SaveChanges(); } catch (DbUpdateConcurrencyException e) { TempData["Param"] = "Changing Tracking"; TempData["Error"] = e.Message; throw e; } catch (DbUpdateException e) { TempData["Param"] = "Changing Tracking"; TempData["Error"] = e.Message; throw e; } // true if added return(Json(new { returnValue = "Removed" })); } else // If it doesn't exist, add it { var newTrackedCve = new TrackedCve() { AspNetUserID = aspNetUserID, CveID = cveID }; try { _context.Add(newTrackedCve); _context.SaveChanges(); } catch (DbUpdateConcurrencyException e) { TempData["Param"] = "Changing Tracking"; TempData["Error"] = e.Message; throw e; } catch (DbUpdateException e) { TempData["Param"] = "Changing Tracking"; TempData["Error"] = e.Message; throw e; } // false if removed return(Json(new { returnValue = "Added" })); } }