Exemple #1
0
        public async Task <CommunityResponseModel> GetCommunities(CommunityCriteriaModel criteriaModel)
        {
            var criteria         = _modelFactory.CreateCommunityCriteria(criteriaModel);
            var communitiesCount = await _communityDao.CountCommunities(criteria).ConfigureAwait(false);

            var communityResponse = new CommunityResponse
            {
                Links = new List <Link>()
                        .AddFirstPage(communitiesCount)
                        .AddLastPage(communitiesCount, criteria.PageSize)
                        .AddNextPage(communitiesCount, criteria.PageSize, criteria.Page)
                        .AddPreviousPage(communitiesCount, criteria.Page)
            };

            if (communitiesCount > 0 && criteria.Page.IsPageInRange(communitiesCount, criteria.PageSize))
            {
                communityResponse.Results = (await _communityDao.GetCommunities(criteria).ConfigureAwait(false))
                                            .Paginate(criteria.Page, criteria.PageSize);
            }
            else
            {
                communityResponse.Results = new List <Community>();
            }


            return(_modelFactory.CreateCommunityResponseModel(communityResponse));
        }
Exemple #2
0
 public CommunityResponseModel CreateCommunityResponseModel(CommunityResponse communityResponse)
 {
     return(CreateResponseModel <Community, CommunityModel, CommunityResponseModel>(communityResponse, CreateCommunityModel));
 }