コード例 #1
0
        private Task <DashBoardCountViewModel> GetItemsAsync()
        {
            var count = new DashBoardCountViewModel();

            count.TotalUserCount = _repository.ToTalUserCount();
            count.RoleCount      = _repository.RolesCount();
            count.ManagerCount   = _repository.ManagerCount();
            count.AdminCount     = _repository.AdminCount();
            count.EndUserCount   = _repository.EnDUserCount();


            return(Task.FromResult(count));
        }
コード例 #2
0
        private Task <DashBoardCountViewModel> GetItemsAsync()
        {
            var count = new DashBoardCountViewModel();
            int Admincount = 0, ManagerCount = 0, NotinRoleCount = 0, EndUserCount = 0;

            count.TotalUserCount    = _repository.ToTalUserCount();
            count.RoleCount         = _repository.RolesCount();
            count.EnabledUserCount  = _repository.EnabledUsers();
            count.DisabledUserCount = _repository.DisabledUsers();

            var users = _userManager.Users;

            foreach (var user in users)
            {
                if (_userManager.IsInRoleAsync(user, "Admin").Result)
                {
                    Admincount++;
                }
                if (_userManager.IsInRoleAsync(user, "Manager").Result)
                {
                    ManagerCount++;
                }
                if (_userManager.IsInRoleAsync(user, "User").Result)
                {
                    EndUserCount++;
                }

                if (!(_userManager.IsInRoleAsync(user, "Admin").Result ||
                      _userManager.IsInRoleAsync(user, "Manager").Result ||
                      _userManager.IsInRoleAsync(user, "User").Result))
                {
                    NotinRoleCount++;
                }
            }

            count.InRole       = Admincount + ManagerCount + EndUserCount;
            count.AdminCount   = Admincount;
            count.ManagerCount = ManagerCount;
            count.EndUserCount = EndUserCount;
            count.NotInRole    = NotinRoleCount;

            count.DisableUserPer = count.DisabledUserCount * 100 / count.TotalUserCount;
            count.EnabledUserPer = count.EnabledUserCount * 100 / count.TotalUserCount;
            count.InRolePer      = count.InRole * 100 / count.TotalUserCount;
            count.NotInROlePer   = count.NotInRole * 100 / count.TotalUserCount;



            return(Task.FromResult(count));
        }