示例#1
0
        public BugAttributes Delete(int id)
        {
            //update this to include comments
            var bug = context.Bugs.Find(id);

            if (bug != null)
            {
                var associatedScreenshots = context.ScreenShots.Where(s => bug.BugId == s.AssociatedBug);
                foreach (var file in associatedScreenshots)
                {
                    firebaseFileStorage.Delete(file.FileName);

                    //var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "screenshots", file.Url);
                    //if (File.Exists(path))
                    //{
                    //    File.Delete(path);
                    //}

                    context.ScreenShots.Remove(file);
                }

                var bugScreenshots = context.Comments.Where(c => c.AssociatedBugId == id);
                if (bugScreenshots != null && bugScreenshots.Count() > 0)
                {
                    //foreach (var screenShot in bugScreenshots)
                    //{
                    context.Comments.RemoveRange(bugScreenshots);
                    //}
                }

                var bugHistory = context.BugHistory.Where(b => b.AssociatedBugId == id);
                context.BugHistory.RemoveRange(bugHistory);

                var projectBug = context.ProjectBugs.FirstOrDefault(b => b.BugId == id);

                context.ProjectBugs.Remove(projectBug);
                context.Bugs.Remove(bug);
                context.SaveChanges();
            }
            return(bug);
        }
示例#2
0
        public ProjectAttributes Delete(int id)
        {
            var project     = context.Projects.Find(id);
            var projectBugs = context.ProjectBugs.Where(b => b.ProjectId == id).ToList();

            foreach (var bug in projectBugs)
            {
                if (bug != null)
                {
                    var associatedScreenshots = context.ScreenShots.Where(s => bug.BugId == s.AssociatedBug);
                    foreach (var file in associatedScreenshots)
                    {
                        firebaseFileStorage.Delete(file.FileName);


                        //var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "screenshots", file.Url);
                        //if (File.Exists(path))
                        //{
                        //    File.Delete(path);
                        //}

                        context.ScreenShots.Remove(file);
                    }
                    var bugToDelete = context.Bugs.Find(bug.BugId);
                    context.Bugs.Remove(bugToDelete);
                    context.ProjectBugs.Remove(bug);
                }
            }



            project.ProjectBugs = projectBugs;
            if (project != null)
            {
                var projectHistory = context.ProjectHistory.Where(p => p.AssociatedProjectId == id);
                context.RemoveRange(projectHistory);
                context.Projects.Remove(project);
                context.SaveChanges();
            }

            return(project);
        }