Exemple #1
0
        public async Task <ActionResult> Index(string userId = "")
        {
            if (string.IsNullOrEmpty(userId) && User.Identity.IsAuthenticated)
            {
                userId = User.Identity.GetUserId();
            }

            if (string.IsNullOrEmpty(userId))
            {
                return(HttpNotFound());
            }

            var user = await userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(HttpNotFound());
            }

            var certificates  = certificatesRepo.GetUserCertificates(userId);
            var coursesTitles = courseManager.GetCourses().ToDictionary(c => c.Id.ToLower(), c => c.Title);

            return(View("List", new UserCertificatesViewModel
            {
                User = user,
                Certificates = certificates,
                CoursesTitles = coursesTitles,
            }));
        }
Exemple #2
0
        public async Task <ActionResult> Profile(string userId)
        {
            var user = usersRepo.FindUserById(userId);

            if (user == null)
            {
                return(HttpNotFound());
            }

            if (!systemAccessesRepo.HasSystemAccess(User.Identity.GetUserId(), SystemAccessType.ViewAllProfiles) && !User.IsSystemAdministrator())
            {
                return(HttpNotFound());
            }

            var logins = await userManager.GetLoginsAsync(userId);

            var userCoursesIds = visitsRepo.GetUserCourses(user.Id).Select(s => s.ToLower());
            var userCourses    = courseManager.GetCourses().Where(c => userCoursesIds.Contains(c.Id.ToLower())).OrderBy(c => c.Title).ToList();

            var allCourses    = courseManager.GetCourses().ToDictionary(c => c.Id, c => c, StringComparer.InvariantCultureIgnoreCase);
            var tempCourseIds = tempCoursesRepo.GetTempCourses()
                                .Select(c => c.CourseId)
                                .Where(c => allCourses.ContainsKey(c))
                                .ToHashSet();
            var certificates = certificatesRepo.GetUserCertificates(user.Id).OrderBy(c => allCourses.GetOrDefault(c.Template.CourseId)?.Title ?? "<курс удалён>").ToList();

            var courseGroups         = userCourses.ToDictionary(c => c.Id, c => groupsRepo.GetUserGroupsNamesAsString(c.Id, userId, User, actual: true, archived: false, maxCount: 10));
            var courseArchivedGroups = userCourses.ToDictionary(c => c.Id, c => groupsRepo.GetUserGroupsNamesAsString(c.Id, userId, User, actual: false, archived: true, maxCount: 10));
            var coursesWithRoles     = (await userRolesRepo.GetUserRolesHistory(userId)).Select(x => x.CourseId.ToLower()).Distinct().ToList();
            var coursesWithAccess    = (await coursesRepo.GetUserAccessHistory(userId)).Select(x => x.CourseId.ToLower()).Distinct().ToList();

            return(View(new ProfileModel
            {
                User = user,
                Logins = logins,
                UserCourses = userCourses,
                CourseGroups = courseGroups,
                CourseArchivedGroups = courseArchivedGroups,
                Certificates = certificates,
                AllCourses = allCourses,
                TempCoursesIds = tempCourseIds,
                CoursesWithRoles = coursesWithRoles,
                CoursesWithAccess = coursesWithAccess
            }));
        }
Exemple #3
0
        public ActionResult Info(string userName)
        {
            var user = db.Users.FirstOrDefault(u => u.Id == userName || u.UserName == userName);

            if (user == null)
            {
                return(RedirectToAction("List"));
            }

            var userCoursesIds = visitsRepo.GetUserCourses(user.Id);
            var userCourses    = courseManager.GetCourses().Where(c => userCoursesIds.Contains(c.Id)).ToList();

            var certificates = certificatesRepo.GetUserCertificates(user.Id);

            return(View(new UserInfoModel {
                User = user,
                GroupsNames = groupsRepo.GetUserGroupsNamesAsString(userCoursesIds.ToList(), user.Id, User, 10),
                Certificates = certificates,
                Courses = courseManager.GetCourses().ToDictionary(c => c.Id, c => c),
                UserCourses = userCourses,
            }));
        }