Beispiel #1
0
        public async Task <UserReadListResponse> GetUsers(UserReadListRequest request)
        {
            var response = new UserReadListResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            Expression <Func <User, bool> >   filter        = x => x.OrganizationId == currentUser.OrganizationId;
            Expression <Func <User, object> > orderByColumn = x => x.Id;

            if (request.SearchTerm.IsNotEmpty())
            {
                filter = x => x.OrganizationId == currentUser.OrganizationId && x.Name.Contains(request.SearchTerm);
            }

            List <User> entities;

            if (request.PagingInfo.Skip < 1)
            {
                entities = await _userRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending);
            }
            else
            {
                entities = await _userRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending);
            }

            if (entities != null)
            {
                for (var i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];
                    var dto    = _userFactory.CreateDtoFromEntity(entity);
                    response.Items.Add(dto);
                }
            }

            response.PagingInfo.Skip           = request.PagingInfo.Skip;
            response.PagingInfo.Take           = request.PagingInfo.Take;
            response.PagingInfo.LastUid        = request.PagingInfo.LastUid;
            response.PagingInfo.IsAscending    = request.PagingInfo.IsAscending;
            response.PagingInfo.TotalItemCount = await _userRepository.Count(filter);

            response.Status = ResponseStatus.Success;
            return(response);
        }
Beispiel #2
0
        public async Task <IActionResult> UserListData(Guid id, int skip, int take)
        {
            var organizationUid = id;

            if (organizationUid.IsEmptyGuid())
            {
                return(Forbid());
            }

            var request = new UserReadListRequest(CurrentUser.Id, organizationUid);

            SetPaging(skip, take, request);
            var response = await OrganizationService.GetUsers(request);

            if (response.Status.IsNotSuccess)
            {
                return(NotFound());
            }

            var result = new DataResult();

            result.AddHeaders("user_name", "email", "invited_at", "last_logged_in_at", "is_active", "created_at");

            for (var i = 0; i < response.Items.Count; i++)
            {
                var item          = response.Items[i];
                var stringBuilder = new StringBuilder();
                stringBuilder.Append($"{item.Uid}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{result.PrepareLink($"/User/Detail/{item.Uid}", item.Name)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.Email}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.InvitedAt)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.LastLoggedInAt)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.IsActive}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.CreatedAt)}{DataResult.SEPARATOR}");

                result.Data.Add(stringBuilder.ToString());
            }

            result.PagingInfo      = response.PagingInfo;
            result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS;

            return(Json(result));
        }
        public static UserReadListRequest GetUserReadListRequest()
        {
            var request = new UserReadListRequest(CurrentUserId, UidOne);

            return(request);
        }