Пример #1
0
        public bool DeleteUser(int id)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();

            var query = new Query <User>().AddFilterClause(u => u.Id == id).Include(u => u.ProjectUsers).Include(u => u.Student);
            var user  = repositoriesContainer.UsersRepository.GetBy(query);

            repositoriesContainer.MessageRepository.DeleteUserMessages(user.Id);

            var projects = user.ProjectUsers.DistinctBy(e => e.ProjectId).Select(e => e.ProjectId);

            foreach (var projectId in projects)
            {
                ProjectManagementService.DeleteUserFromProject(id, projectId);
            }

            if (user.Student != null)
            {
                var acp = user.Student.AssignedCourseProjects.Select(e => e.CourseProjectId);
                foreach (var acpId in acp)
                {
                    CPManagementService.DeleteUserFromAcpProject(id, acpId);
                }

                var subjects = repositoriesContainer.RepositoryFor <SubjectStudent>()
                               .GetAll(new Query <SubjectStudent>(e => e.StudentId == id));

                foreach (var subjectS in subjects)
                {
                    repositoriesContainer.RepositoryFor <SubjectStudent>().Delete(subjectS);
                }

                var diplomas = Context.AssignedDiplomProjects.Where(e => e.StudentId == id).ToList();

                var diplomasRessList = Context.DiplomPercentagesResults.Where(e => e.StudentId == id).ToList();

                foreach (var diploma in diplomas)
                {
                    Context.AssignedDiplomProjects.Remove(diploma);
                    Context.SaveChanges();
                }

                foreach (var diplomasRes in diplomasRessList)
                {
                    Context.DiplomPercentagesResults.Remove(diplomasRes);
                    Context.SaveChanges();
                }
            }

            CPManagementService.DeletePercenageAndVisitStatsForUser(id);

            repositoriesContainer.ApplyChanges();
            var result = AccountManagementService.DeleteAccount(user.UserName);

            repositoriesContainer.ApplyChanges();

            return(result);
        }
Пример #2
0
        public bool DeleteUser(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var query = new Query <User>().AddFilterClause(u => u.Id == id).Include(u => u.ProjectUsers);
                var user  = repositoriesContainer.UsersRepository.GetBy(query);

                repositoriesContainer.MessageRepository.DeleteUserMessages(user.Id);

                var projects = user.ProjectUsers.DistinctBy(e => e.ProjectId).Select(e => e.ProjectId);
                foreach (var projectId in projects)
                {
                    ProjectManagementService.DeleteUserFromProject(id, projectId);
                }

                var result = AccountManagementService.DeleteAccount(user.UserName);
                repositoriesContainer.ApplyChanges();

                return(result);
            }
        }