protected override async Task <ILayoutViewModelBase> GetViewModelForCreateEditAsync(T item, string returnUrl, eAction action, string parentId, string param)
        {
            var pageSizeConfig = new PageSizeConfig();

            var(title1, title2, title3) = await GetTitle123Async(item, parentId, action);

            var pageSize   = pageSizeConfig.Value;
            var contentsVm = GetLayoutContentsViewModelForCreateEdit(item, title1, title2, title3, pageSize, parentId: parentId);
            var vm         = await GetLayoutViewModelBase <LayoutWithContentViewModelBase <TLayoutContentsCreateEditViewModel> >(title1);

            vm.AllowKnockoutJs  = GetAllowKnockoutJs(param);
            vm.ReturnUrl        = returnUrl;
            vm.ContentViewModel = contentsVm;

            return(vm);
        }
        protected override async Task <IPagedList <AspNetUserRole> > GetItemsAsync(string parentId, int page, bool desc, int sortColumn, string search, string param)
        {
            var pageSize = new PageSizeConfig();
            var roles    = await UserManager.GetRolesAsync(parentId);

            var user = await UserManager.FindByIdAsync(parentId);

            return(roles
                   .Where(r => search == null || r.Contains(search))
                   .OrderBy(r => r)
                   .Select(r => new AspNetUserRole
            {
                Id = r,
                RoleName = r,
                AspNetUserId = parentId,
                UserName = user.UserName,
                Email = user.Email
            })
                   .ToPagedList(page, pageSize.Value));
        }
Ejemplo n.º 3
0
        protected override async Task <IPagedList <AspNetUser> > GetItemsAsync(string parentId, int page, bool desc, int sortColumn, string search, string param)
        {
            var pageSize = new PageSizeConfig();
            var items    = await UserManager.Users
                           .OrderBy(r => r.UserName)
                           .Where(r => search == null || r.UserName.Contains(search))
                           .ToListAsync();

            var tmpItems = items
                           .Select(r => new AspNetUser
            {
                Id       = r.Id,
                UserName = r.UserName,
                Email    = r.Email
            })
                           .ToList();

            await tmpItems.ForEachAsync(async tmpItem =>
            {
                var roles = await GetRolesForUserAsync(tmpItem.UserName);

                roles.ToList().ForEach(r => tmpItem.AspNetUserRoles.Add(new AspNetUserRole
                {
                    Id           = r,
                    RoleName     = r,
                    AspNetUserId = tmpItem.Id,
                    UserName     = tmpItem.UserName,
                    Email        = tmpItem.Email
                }));
            });

            tmpItems.ForEach(tmpItem =>
            {
                tmpItem.AspNetUserRoles.OrderBy(r => r.RoleName);
            });

            return(tmpItems
                   .OrderBy(r => r.HasRole)
                   .ThenBy(r => r.UserName)
                   .ToPagedList(page, pageSize.Value));
        }