Esempio n. 1
0
        /// <summary>
        /// 根据课程 Id ,获取全部等待授权的用户或者用户组
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List <CourseAuthorizationVM> GetToBeAuthorizeCollection(List <ApplicationRole> authorizedRoleCollection, List <ApplicationUser> authorizedUserCollection)
        {
            var roleCollection = _roleManager.Roles;
            var userCollection = _userManager.Users;
            var tobeAuthorizedItemCollection = new List <CourseAuthorizationVM>();

            foreach (var item in roleCollection)
            {
                if (!authorizedRoleCollection.Contains(item))
                {
                    var courseAuthorizationViewModel = new CourseAuthorizationVM();
                    courseAuthorizationViewModel.Id          = item.Id;
                    courseAuthorizationViewModel.Name        = item.Name;
                    courseAuthorizationViewModel.DisplayName = item.DisplayName;
                    courseAuthorizationViewModel.SortCode    = item.SortCode;
                    courseAuthorizationViewModel.IsUser      = false;

                    tobeAuthorizedItemCollection.Add(courseAuthorizationViewModel);
                }
            }

            // 关闭待选授权元素的用户,在选择用户时,通过关键词来选
            //foreach (var item in userCollection)
            //{
            //    if (!authorizedUserCollection.Contains(item))
            //    {
            //        var courseAuthorizationViewModel = new CourseAuthorizationVM();
            //        courseAuthorizationViewModel.Id          = item.Id;
            //        courseAuthorizationViewModel.Name        = item.UserName;
            //        courseAuthorizationViewModel.DisplayName = item.ChineseFullName;
            //        courseAuthorizationViewModel.SortCode    = "";
            //        courseAuthorizationViewModel.IsUser      = true;

            //        tobeAuthorizedItemCollection.Add(courseAuthorizationViewModel);
            //    }
            //}

            return(tobeAuthorizedItemCollection);
        }
Esempio n. 2
0
        public async Task <CourseAuthorizationSelectorVM> GetCourseAuthorizationSelectorVMAsync(Guid id, bool getTobeItems, AuthorizationTypeEnum authorizationType)
        {
            var course = await _boRepository.GetSingleAsyn(id);

            var authorizedCollection     = new List <CourseAuthorizationVM>();
            var authorizedRoleCollection = new List <ApplicationRole>();
            var authorizedUserCollection = new List <ApplicationUser>();

            // 授权角色组
            var courseWithRoleCollection = await _courseWithRolesRepository.GetAllIncludingAsyn(x => x.ApplicationRole, y => y.Course);

            foreach (var item in courseWithRoleCollection.Where(x => x.Course.Id == id && x.AuthorizationTypeEnum == authorizationType))
            {
                var courseAuthorizationViewModel = new CourseAuthorizationVM();
                courseAuthorizationViewModel.Id          = item.ApplicationRole.Id;
                courseAuthorizationViewModel.Name        = item.ApplicationRole.Name;
                courseAuthorizationViewModel.DisplayName = item.ApplicationRole.DisplayName;
                courseAuthorizationViewModel.SortCode    = item.ApplicationRole.SortCode;
                courseAuthorizationViewModel.IsUser      = false;
                authorizedRoleCollection.Add(item.ApplicationRole);
                authorizedCollection.Add(courseAuthorizationViewModel);
            }

            // 授权用户
            var courseWithUserCollection = await _courseWithUsersRepository.GetAllIncludingAsyn(x => x.ApplicationUser, y => y.Course);

            foreach (var item in courseWithUserCollection.Where(x => x.Course.Id == id && x.AuthorizationTypeEnum == authorizationType))
            {
                var courseAuthorizationViewModel = new CourseAuthorizationVM();
                courseAuthorizationViewModel.Id          = item.ApplicationUser.Id;
                courseAuthorizationViewModel.Name        = item.ApplicationUser.UserName;
                courseAuthorizationViewModel.DisplayName = item.ApplicationUser.ChineseFullName;
                courseAuthorizationViewModel.SortCode    = "";
                courseAuthorizationViewModel.IsUser      = true;
                courseAuthorizationViewModel.Description = await _GetCourseAuthorizationVMDescriptionByUser(item.ApplicationUser);

                authorizedUserCollection.Add(item.ApplicationUser);
                authorizedCollection.Add(courseAuthorizationViewModel);
            }

            var courseAuthorizationSelectorVM = new CourseAuthorizationSelectorVM();

            courseAuthorizationSelectorVM.CourseID   = course.Id;
            courseAuthorizationSelectorVM.CourseName = course.Name;

            // 合成
            int count = 0;

            foreach (var item in authorizedCollection.OrderBy(x => x.Name))
            {
                item.OrderNumber = (++count).ToString();
                courseAuthorizationSelectorVM.BeAuthorizationedItemCollection.Add(item);
            }

            if (getTobeItems)
            {
                var tobeAuthorizedCollection = GetToBeAuthorizeCollection(authorizedRoleCollection, authorizedUserCollection);
                foreach (var item in tobeAuthorizedCollection.OrderBy(x => x.Name))
                {
                    courseAuthorizationSelectorVM.ToBeAuthorizationedItemCollection.Add(item);
                }
            }

            // 附带权限清单
            courseAuthorizationSelectorVM.AuthorizationType = authorizationType;
            courseAuthorizationSelectorVM.AuthorizationTypeForCourseCollection = GetAuthorizationTypeForCourseCollection();
            foreach (var item in courseAuthorizationSelectorVM.AuthorizationTypeForCourseCollection)
            {
                if (item.AuthorizationType == authorizationType)
                {
                    item.IsActive = true;
                }
            }

            return(courseAuthorizationSelectorVM);
        }