Ejemplo n.º 1
0
        public async Task <UserInfoAdminIndexViewModel> GetIndexViewAsync(UserInformationAdminSearchDto searchDto,
                                                                          PageListActionDto pageListActionDto, Guid?id)
        {
            var indexViewModel = new UserInfoAdminIndexViewModel();

            if (pageListActionDto == null)
            {
                pageListActionDto = new PageListActionDto();
            }
            if (searchDto == null)
            {
                searchDto = new UserInformationAdminSearchDto();
            }

            indexViewModel.SearchDto = searchDto;

            //This section used to set ascending or descending order
            indexViewModel.SortDto.FirstName =
                String.IsNullOrEmpty(pageListActionDto.SortOrder) ? "FirstName_desc" : "";

            indexViewModel.SortDto.LastName =
                pageListActionDto.SortOrder == "LastName" ? "LastName_desc" : "LastName";

            indexViewModel.SortDto.UserName =
                pageListActionDto.SortOrder == "UserName" ? "UserName_desc" : "UserName";

            indexViewModel.Title       = "Manage " + _TitleDesc + "s";
            pageListActionDto.PageSize = 10;

            indexViewModel.PageListAction.CurrentSort = pageListActionDto.SortOrder;

            //var userInformations = await _unitOfWork.ApplicationUserRepository.GetAsync(ExpressionBuilder<ApplicationUser>.GetExpression(searchDto),
            //    GetSortOrder(pageListActionDto.SortOrder), "");

            var userInformations = await _unitOfWork.ApplicationUserRepository.GetAsync(await UserSearch(searchDto),
                                                                                        GetSortOrder(pageListActionDto.SortOrder), "");

            indexViewModel.UserInformations = await userInformations
                                              .ToPagedListAsync((pageListActionDto.Page ?? 1), pageListActionDto.PageSize);

            //Add items for selected user
            if (id != null)
            {
                var selectedUserInformation = await _unitOfWork.ApplicationUserRepository.SingleOrDefaultAsync(
                    u => u.Id == id, "ApplicationUserUserRoles,ApplicationUserUserRoles.ApplicationUserRole");

                indexViewModel.SelectedUserInformation = selectedUserInformation;
            }

            return(indexViewModel);
        }
Ejemplo n.º 2
0
        public UserInfoAdminIndexViewModel GetIndexView(string sortOrder, string currentFilter, string searchString,
                                                        int?page, int?id, int pageSize = 10)
        {
            var pageListAction = new UserInfoAdminIndexPageListAction(pageSize: pageSize, sortOrder: sortOrder, currentFilter: currentFilter, searchString: searchString, page: page, id: id);

            var userInformation             = pageListAction.GetUserInfos(_unitOfWork);
            var userInfoAdminIndexViewModel = new UserInfoAdminIndexViewModel(pageListAction, userInformation.Result);

            if (pageListAction.UserInformationId != null)
            {
                userInfoAdminIndexViewModel.UserRoles = userInformation
                                                        .Result.Single(i => id != null && i.UserInformationId == id.Value).UserInformationUserRoles.Select(u => u.UserRole);
                pageListAction.LanId = userInformation.Result.Single(i => id != null && i.UserInformationId == id.Value).LanId;
            }

            userInfoAdminIndexViewModel.Title = "User Administration";

            return(userInfoAdminIndexViewModel);
        }