public Issue Delete(int id) { var issue = _context.Issues.Find(id); if (issue != null) { var issueScreenshots = _context.ScreenShots.Where(s => s.AssociatedIssue == id); foreach (var screenshot in issueScreenshots) { fireBaseStorage.Delete(screenshot.FileName); _context.ScreenShots.Remove(screenshot); } var issueComments = _context.Comments.Where(c => c.AssociatedIssueId == id); if (issueComments != null && issueComments.Count() > 0) { _context.Comments.RemoveRange(issueComments); } var issueHistories = _context.IssueHistory.Where(i => i.AssociatedIssueId == id); if (issueHistories != null && issueHistories.Count() > 0) { _context.IssueHistory.RemoveRange(issueHistories); } var projectIssue = _context.ProjectIssues.FirstOrDefault(i => i.IssueId == id); _context.ProjectIssues.Remove(projectIssue); _context.Remove(issue); _context.SaveChanges(); } return(issue); }
public Project Delete(int id) { var project = _context.Projects.Find(id); var projectIssues = _context.ProjectIssues.Where(p => p.ProjectId == id).ToList(); foreach (var issue in projectIssues) { Console.WriteLine($"Issue Ids: {issue.IssueId}"); } foreach (var issue in projectIssues) { Console.WriteLine($"Issue TO Be Deleted {issue.IssueId}"); if (issue != null) { var projectScreenshots = _context.ScreenShots.Where(s => s.AssociatedIssue == issue.IssueId); foreach (var screenshot in projectScreenshots) { firebaseStorage.Delete(screenshot.FileName); _context.ScreenShots.Remove(screenshot); } var issueToDelete = _context.Issues.Find(issue.Id); _context.Issues.Remove(issueToDelete); _context.ProjectIssues.Remove(issue); Console.WriteLine("Scuess"); } } project.ProjectIssues = projectIssues; if (project != null) { var projectHistory = _context.ProjectHistory.Where(p => p.AssociatedProjectId == id); _context.ProjectHistory.RemoveRange(projectHistory); _context.Projects.Remove(project); _context.SaveChanges(); } return(project); }