コード例 #1
0
        public ListOfUsersWithRolesVm GetUsersAndTheirsRoles(int pageSize, int pageNo, string searchString, string roleId)
        {
            var users = new List <UserAndRoleVm>();

            if (roleId == "Nie wybieram żadnej roli")
            {
                users = _usersRolesAndScoresRepo.GetUsers().Where(u => u.UserName.StartsWith(searchString))
                        .ProjectTo <UserAndRoleVm>(_mapper.ConfigurationProvider).ToList();
            }
            else
            {
                users = _usersRolesAndScoresRepo.GetUsers().Where(u => u.UserName.StartsWith(searchString) &&
                                                                  u.UserRoles.Where(r => r.RoleId == roleId).Any())
                        .ProjectTo <UserAndRoleVm>(_mapper.ConfigurationProvider).ToList();
            }
            var usersToShow = users.Skip(pageSize * (pageNo - 1)).Take(pageSize).ToList();
            ApplicationRoleVm roleToList = new ApplicationRoleVm()
            {
                Name = "Nie wybieram żadnej roli"
            };
            var roles = _usersRolesAndScoresRepo.GetRoles().ProjectTo <ApplicationRoleVm>
                            (_mapper.ConfigurationProvider).ToList();

            roles.Add(roleToList);
            ListOfUsersWithRolesVm listOfUsersWithRolesVm = new ListOfUsersWithRolesVm()
            {
                UsersAndTheirRoles = usersToShow,
                AllRoles           = roles,
                Count        = users.Count,
                CurrentPage  = pageNo,
                PageSize     = pageSize,
                SearchString = searchString,
                RoleId       = roleId
            };

            return(listOfUsersWithRolesVm);
        }
コード例 #2
0
ファイル: StatsService.cs プロジェクト: ilona1290/Web-Quiz
        public StatsOfUsersVm GetStatsAboutUsers()
        {
            List <string> superAdmins = new List <string>();
            List <string> admins      = new List <string>();
            List <string> usualUsers  = new List <string>();
            var           users       = _usersRolesAndScoresRepo.GetUsers().ProjectTo <UserAndRoleVm>
                                            (_mapper.ConfigurationProvider).ToList();

            foreach (var item in users)
            {
                if (item.UserRoles[0].Role.Id == "SuperAdmin")
                {
                    superAdmins.Add(item.UserName);
                }
                else if (item.UserRoles[0].Role.Id == "Admin")
                {
                    admins.Add(item.UserName);
                }
                else if (item.UserRoles[0].Role.Id == "User")
                {
                    usualUsers.Add(item.UserName);
                }
            }
            var bestScores = _usersRolesAndScoresRepo.GetBestResults().ProjectTo <ScoreVm>
                                 (_mapper.ConfigurationProvider).ToList();
            var            sortedList     = bestScores.OrderBy(i => i.BestResult).Reverse().ToList();
            StatsOfUsersVm statsOfUsersVm = new StatsOfUsersVm()
            {
                NumberOfRegisteredUsers = users.Count,
                NumberOfSuperAdmins     = superAdmins.Count(),
                EmailsOfSuperAdmins     = superAdmins,
                NumberOfAdmins          = admins.Count(),
                EmailsOfAdmins          = admins,
                NumberOfUsualUser       = usualUsers.Count(),
                EmailsOfUsualUser       = usualUsers,
                TheBestScore            = sortedList[0].BestResult,
                EmailOfTheBestPlayer    = sortedList[0].UserLogin,
                TheWorstScore           = sortedList[sortedList.Count() - 1].BestResult,
                EmailOfTheWorstPlayer   = sortedList[sortedList.Count() - 1].UserLogin
            };

            return(statsOfUsersVm);
        }