Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageDetails"></param>
        /// <param name="subscriptionId"></param>
        /// <returns></returns>
        public async Task <PagedResultSet <DomainModel.Contact> > MyContacts(Models.Common.PageDetails pageDetails, Guid?subscriptionId)
        {
            Expression <Func <DomainModel.Contact, bool> > expression = contact => true;

            if (subscriptionId != null && subscriptionId != Guid.Empty)
            {
                expression = contact => contact.SubscriptionId == subscriptionId;
            }

            if (!string.IsNullOrWhiteSpace(pageDetails?.SearchText))
            {
                expression = expression.And(contact => (contact.FirstName.Contains(pageDetails.SearchText) ||
                                                        contact.LastName.Contains(pageDetails.SearchText) ||
                                                        contact.Email.Contains(pageDetails.SearchText) ||
                                                        contact.PhoneNumber.Contains(pageDetails.SearchText) ||
                                                        contact.GroupContactAssociations.Any(asso => asso.Group.Name.Contains(pageDetails.SearchText))));
            }

            var contacts = await Repository.GetAsync(expression);

            var skip = pageDetails?.PageSize != null && pageDetails?.PageNo != null ?
                       pageDetails.PageSize.Value * (pageDetails.PageNo.Value - 1) :
                       pageDetails?.PageSize;

            return(PagedResultSet <DomainModel.Contact> .Construct(contacts, skip, pageDetails?.PageSize));
        }
        public async Task <PagedResultSet <MovieResponseModel> > GetMoviesByPagination(int pageSize = 20, int page = 0, string title = "")
        {
            // check if title parameter is null or empty, if not then construct a Expression with Contains method
            // contains method will transalate to SQL like
            Expression <Func <Movie, bool> > filterExpression = null;

            if (!string.IsNullOrEmpty(title))
            {
                filterExpression = movie => title != null && movie.Title.Contains(title);
            }
            //  // we are gonna call GetPagedData method from repository;
            // pass the order by column, here we are ordering our result by movie title
            // pass the above filter expression
            var pagedMovies = await _movieRepository.GetPagedData(page, pageSize, movies => movies.OrderBy(m => m.Title), filterExpression);

            // once you get movies from repository , convert them in to MovieResponseModel List
            var pagedMovieResponseModel = new List <MovieResponseModel>();

            foreach (var movie in pagedMovies)
            {
                pagedMovieResponseModel.Add(new MovieResponseModel
                {
                    Id          = movie.Id,
                    Title       = movie.Title,
                    PosterUrl   = movie.PosterUrl,
                    ReleaseDate = movie.ReleaseDate.Value
                });
            }
            // Pass the List of MovieResponseModel to our PagedResultSet class so that it can display the data along with page numbers
            var movies = new PagedResultSet <MovieResponseModel>(pagedMovieResponseModel, page, pageSize, pagedMovies.TotalCount);

            return(movies);
        }
Beispiel #3
0
        public async Task <PagedResultSet <InitiativeInfo> > GetInitiativesByStakeholderPersonIdAsync(int personId, string filter, int pageNumber, int pageSize)
        {
            return(await ExecuteAsync(async client =>
            {
                var response = await client.GetAsync($"?View=Mine");
                if (response.IsSuccessStatusCode)
                {
                    var ideaString = await response.Content.ReadAsStringAsync();

                    string totalCountString = response.Headers.GetValues("X-Total-Count").FirstOrDefault();
                    int totalCount = 0;
                    if (!string.IsNullOrWhiteSpace(totalCountString))
                    {
                        int.TryParse(totalCountString, out totalCount);
                    }

                    var contractResolver = new InitiativeContractResolver();
                    var settings = new JsonSerializerSettings()
                    {
                        ContractResolver = contractResolver
                    };
                    var returnValues = JsonConvert.DeserializeObject <IEnumerable <InitiativeInfo> >(ideaString, settings).ToList();
                    return PagedResultSet.Create(returnValues, pageNumber, pageSize, totalCount);
                }
                else
                {
                    var ex = new InvalidOperationException($"Response from remote webservice did not indicate success ({response.StatusCode})");
                    ex.Data["HttpResponse"] = response;
                    throw ex;
                }
            }));
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="subscriptionId"></param>
        /// <param name="pageDetails"></param>
        /// <returns></returns>
        public async Task <PagedResultSet <Models.Campaign.CampaignSummary> > GetMyCampaigns(Guid?subscriptionId, PageDetails pageDetails)
        {
            Expression <Func <DomainModel.Campaign, bool> > expression = campaign => true;

            if (subscriptionId.HasValue && subscriptionId.Value != Guid.Empty)
            {
                expression = campaign => campaign.SubscriptionId == subscriptionId;
            }

            var campaigns = await Repository.GetAsync(expression);

            if (!campaigns.Any())
            {
                return(PagedResultSet <Models.Campaign.CampaignSummary> .Construct(new List <Models.Campaign.CampaignSummary>(), null, null));
            }

            var campaignsSummary = _mapper.Map <IEnumerable <Models.Campaign.CampaignSummary> >(campaigns);
            var IdentifierFilter = campaignsSummary.Select(campaignSummary => new Models.Subscription.Input.IdentifierFilter {
                SubscriptionId = campaignSummary.SubscriptionId,
                GroupId        = campaignSummary.GroupId
            }).ToList();
            var subscriptionsAndGroupSummary = await _subscriptionServiceClient.GetSubscriptionsAndGroupSummaryByIdAsync(IdentifierFilter);

            campaignsSummary.ToList().ForEach(summary =>
            {
                var subscriptionSummary = subscriptionsAndGroupSummary.First(subscriptionAndGroupSummary => subscriptionAndGroupSummary.Id == summary.SubscriptionId);
                summary.Subscription    = _mapper.Map <SubscriptionWithGroupSummary, Subscription>(subscriptionSummary);
                summary.GroupSummary    = summary.GroupId != null ? subscriptionSummary.GroupSummary.First(group => group.Id == summary.GroupId) : null;
            });

            var skip = pageDetails.PageSize.HasValue ? pageDetails.PageSize.Value * (pageDetails.PageNo.Value - 1) : pageDetails.PageSize.GetValueOrDefault();

            return(PagedResultSet <Models.Campaign.CampaignSummary> .Construct(campaignsSummary, skip, pageDetails.PageSize.GetValueOrDefault()));
        }
        public IActionResult GetMovieByPagination(int index, string title = "")
        {
            var movies          = _movieService.GetMoviesByPagination(index, 20, title).ToList();
            var totalMovies     = _movieService.GetMovieByTitle(title).Count();
            var PageResultmovie = new PagedResultSet <Movie>(index, 20, totalMovies, movies);

            return(Ok(PageResultmovie));
        }
Beispiel #6
0
 public Task <PagedResultSet <TEntity> > Search(PagedRequest pagedRequest, Func <IQueryable <TEntity>, IQueryable <TEntity> > query)
 {
     return(PagedResultSet <TEntity> .CreateAsync(
                query(Context.Set <TEntity>().AsQueryable()),
                pagedRequest.PageNumber,
                pagedRequest.PageSize,
                x => x.ToListAsync()));
 }
        public Task <PagedResultSet <PrimaryItem> > GetAllWithSecondaryItemBySecondaryItemIdAsync(long secondaryItemId, PagedRequest pagedRequest)
        {
            var query = ServiceContext.PrimaryItems
                        .Include(e => e.SecondaryItem)
                        .Where(e => e.SecondaryItemId == secondaryItemId);

            return(PagedResultSet <PrimaryItem> .CreateAsync(query, pagedRequest.PageNumber, pagedRequest.PageSize, x => x.ToListAsync()));
        }
        public Task <PagedResultSet <PrimaryItem> > GetAllWithSecondaryItemPagedAsync(PrimaryItemPagedRequest pagedRequest)
        {
            var query = ServiceContext.PrimaryItems
                        .Include(x => x.SecondaryItem)
                        .Where(x => string.IsNullOrWhiteSpace(pagedRequest.Query) || x.Name.Contains(pagedRequest.Query))
                        .OrderBy(pagedRequest.OrderBy + $" {pagedRequest.SortOrder}");

            return(PagedResultSet <PrimaryItem> .CreateAsync(query, pagedRequest.PageNumber, pagedRequest.PageSize, x => x.ToListAsync()));
        }
Beispiel #9
0
        public IActionResult MyFavoritedMovies(int index, int pageSize = 20, string filter = "")
        {
            var users      = _userService.GetUserPagination(index, pageSize, filter);
            var userDto    = _mapper.Map <IEnumerable <User>, IEnumerable <UserDTO> >(users);
            var totalUsers = _userService.GetAllUsers(filter);
            var pageSet    = new PagedResultSet <UserDTO>(page: index, pageSize: pageSize, totalRecords: totalUsers, data: userDto);

            return(Ok(pageSet));
        }
Beispiel #10
0
        public async Task <PagedResultSet <InitiativeInfo> > GetInitiativesByStakeholderPersonIdAsync(int personId,
                                                                                                      string filter, int pageNumber, int pageSize)
        {
            var query = _initiativeContext.Initiatives
                        .Where(x => x.Stakeholders.Any(y => y.PersonId == personId));

            var initiatives = CreateInitiativeInfoQuery(query, filter);

            return(await PagedResultSet.Create(initiatives, pageNumber, pageSize));
        }
Beispiel #11
0
        protected override async Task <PagedResultSet <SpaceView> > HandleInput(FindParams input)
        {
            using (var connection = database.GetConnection()) {
                ISpaceRepo spaceRepo = database.GetRepo <ISpaceRepo>(connection);

                PagedResultSet <Space> spaces = await spaceRepo.Find(input.Pagination?.PageNumber ?? 0, input.Pagination?.PageSize ?? Post.PageSize);

                return(new PagedResultSet <SpaceView>(spaces.Select(s => mapper.Map(s)), spaces.Pagination));
            }
        }
Beispiel #12
0
        public Task <PagedResultSet <TEntity> > Search(PagedRequest pagedRequest, Expression <Func <TEntity, bool> > predicate)
        {
            var query = Context.Set <TEntity>().Where(predicate);

            return(PagedResultSet <TEntity> .CreateAsync(
                       query,
                       pagedRequest.PageNumber,
                       pagedRequest.PageSize,
                       x => x.ToListAsync()));
        }
Beispiel #13
0
        public Task <PagedResultSet <TEntity> > GetAllAsync(PagedRequest pagedRequest)
        {
            var query = Context.Set <TEntity>();

            return(PagedResultSet <TEntity> .CreateAsync(
                       query,
                       pagedRequest.PageNumber,
                       pagedRequest.PageSize,
                       x => x.ToListAsync()));
        }
Beispiel #14
0
        public IActionResult GetMovieByPage(int index = 1, int pageSize = 20, string filter = "")
        {
            IList <MovieDTO> movieDtos = new List <MovieDTO>();
            var movies          = _movieService.GetMoviesByPagination(index, pageSize, filter).ToList();
            var movieDto        = _mapper.Map <IList <Movie>, IList <MovieDTO> >(movies, movieDtos);
            var totalMovies     = _movieService.GetMovieByTitle(filter).Count();
            var PageResultmovie = new PagedResultSet <MovieDTO>(index, 20, totalMovies, movieDto);

            return(Ok(PageResultmovie));
        }
Beispiel #15
0
        public async Task <PagedResultSet <MovieResponseModel> > GetAllMoviePurchasesByPagination(int pageSize = 50, int page = 0)
        {
            var totalPurchases = await _purchaseRepository.GetCountAsync();

            var purchases = await _purchaseRepository.GetAllPurchases(pageSize, page);

            var data            = _mapper.Map <List <MovieResponseModel> >(purchases);
            var purchasedMovies = new PagedResultSet <MovieResponseModel>(data, page, pageSize, totalPurchases);

            return(purchasedMovies);
        }
Beispiel #16
0
        public async Task PagedResultSet_PageNumber_ReturnsCorrectValue(int pageNumber, int expectedResult)
        {
            IQueryable <string> values = new List <string>
            {
                "a", "b", "c", "d", "e", "f"
            }.AsQueryable();

            var result = await PagedResultSet <string> .CreateAsync(values, pageNumber, 1, async x => x.ToList());

            result.PageNumber.Should().Be(expectedResult);
        }
Beispiel #17
0
        public async Task PagedResultSet_ItemCount_ReturnsCorrectValue(int pageNumber, int pageSize, int itemCount)
        {
            IQueryable <string> values = new List <string>
            {
                "a", "b", "c", "d", "e", "f"
            }.AsQueryable();

            var result = await PagedResultSet <string> .CreateAsync(values, pageNumber, pageSize, async x => x.ToList());

            result.Items.Count().Should().Be(itemCount);
        }
Beispiel #18
0
        public IActionResult ShowAllMovies([FromQuery] PageDTO page)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("failed"));
            }
            var totalRecords = _adminService.TotalMovieRecords(page.Filter);
            var movies       = _adminService.ShowAllMovies(page);
            var movieDto     = _mapper.Map <IEnumerable <Movie>, IEnumerable <MovieDTO> >(movies);
            var pageData     = new PagedResultSet <MovieDTO>(page: page.Index, pageSize: page.PageSize, totalRecords: totalRecords, data: movieDto);

            return(Ok(pageData));
        }
Beispiel #19
0
        public PagedResultSet <T> GetPagedData(int currentPage, int pageSize)
        {
            IQueryable <T> query = _dbContext.Set <T>();

            var totalRowCount    = query.Count();
            var currentPageIndex = currentPage;
            var skip             = (currentPageIndex - 1) * pageSize;
            var data             = query.Skip(skip).Take(pageSize).ToList();

            var pagedResult = new PagedResultSet <T>(currentPageIndex, pageSize, totalRowCount, data);

            return(pagedResult);
        }
Beispiel #20
0
        public IActionResult GetAllUserInfo([FromQuery] PageDTO page)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(""));
            }
            var totalRecords = _adminService.TotalUserRecords(page.Filter);
            var users        = _adminService.GetAllUserInfo(page);
            var userDto      = _mapper.Map <IEnumerable <User>, IEnumerable <UserDTO> >(users);
            var pageData     = new PagedResultSet <UserDTO>(page: page.Index, pageSize: page.PageSize, totalRecords: totalRecords, data: userDto);

            return(Ok(pageData));
        }
Beispiel #21
0
        public IActionResult GetAllPurchasesForMovie([FromQuery] PageDTO page)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(""));
            }
            var totalRecords = _adminService.TotalPurchaseMovieRecords(page.Filter);
            var purchases    = _adminService.GetAllPuchasesForMovie(page);
            var purchasesDto = _mapper.Map <IEnumerable <Purchase>, IEnumerable <PurchaseDTO> >(purchases);
            var pageData     = new PagedResultSet <PurchaseDTO>(page: page.Index, pageSize: page.PageSize, totalRecords: totalRecords, data: purchasesDto);

            return(Ok(pageData));
        }
Beispiel #22
0
        public async Task <PagedResultSet <IssueInfo> > GetIssuesAsync(string filter, int pageNumber, int pageSize)
        {
            return(await ExecuteAsync(async client =>
            {
                var queryBuilder = new StringBuilder();
                if (!string.IsNullOrWhiteSpace(filter))
                {
                    queryBuilder.Append(queryBuilder.Length == 0 ? "?" : "&");
                    queryBuilder.Append("contains=");
                    queryBuilder.Append(filter);
                }
                if (pageNumber > 0)
                {
                    queryBuilder.Append(queryBuilder.Length == 0 ? "?" : "&");
                    queryBuilder.Append("page=");
                    queryBuilder.Append(pageNumber);
                }
                if (pageSize > 0)
                {
                    queryBuilder.Append(queryBuilder.Length == 0 ? "?" : "&");
                    queryBuilder.Append("pageSize=");
                    queryBuilder.Append(pageSize);
                }

                var response = await client.GetAsync(queryBuilder.ToString());
                if (response.IsSuccessStatusCode)
                {
                    string totalCountString = response.Headers.GetValues("X-Total-Count").FirstOrDefault();
                    int totalCount = 0;
                    if (!string.IsNullOrWhiteSpace(totalCountString))
                    {
                        int.TryParse(totalCountString, out totalCount);
                    }

                    var ideaString = await response.Content.ReadAsStringAsync();
                    var contractResolver = new IssueContractResolver();
                    var settings = new JsonSerializerSettings()
                    {
                        ContractResolver = contractResolver
                    };
                    var returnValues = JsonConvert.DeserializeObject <IEnumerable <IssueInfo> >(ideaString, settings).ToList();
                    return PagedResultSet.Create(returnValues, pageNumber, pageSize, totalCount);
                }
                else
                {
                    var ex = new InvalidOperationException($"Response from remote webservice did not indicate success ({response.StatusCode})");
                    ex.Data["HttpResponse"] = response;
                    throw ex;
                }
            }));
        }
Beispiel #23
0
        public async Task <PagedResultSet <User> > GetAllUsersByPagination(int pageSize = 20, int page = 0, string lastName = "")
        {
            Expression <Func <User, bool> > filter = null;

            if (!string.IsNullOrEmpty(lastName))
            {
                filter = user => lastName != null && user.LastName == lastName;
            }

            var pagedUsers = await _userRepository.GetPagedData(page, pageSize, user => user.OrderBy(u => u.LastName), filter);

            var pagedResults = new PagedResultSet <User>(pagedUsers, page, pageSize, pagedUsers.TotalCount);

            return(pagedResults);
        }
        public IHttpActionResult GetDepartments([FromUri] int pageSize = 8, [FromUri] int page = 1,
                                                [FromUri] string name  = "")
        {
            var totalDepartmentsCount = _departmentService.GetTotalDepartments(name);
            var departments           = _departmentService.GetDepartmentsPagination(pageSize, page, name);
            var pagedDepartments      = new PagedResultSet <DepartmentDTO>(page, pageSize, totalDepartmentsCount,
                                                                           Mapper
                                                                           .Map <IList <Department>, IList <DepartmentDTO>
                                                                                 >(departments.ToList()));
            var response = pagedDepartments.Data.Any()
                ? Request.CreateResponse(HttpStatusCode.OK, pagedDepartments)
                : Request.CreateResponse(HttpStatusCode.NotFound, "No Departments for your query");

            return(ResponseMessage(response));
        }
Beispiel #25
0
        /// <summary>
        /// Adds the paging headers.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="model">The model.</param>
        private void AddPagingHeaders <TResult>(PagedResultSet <TResult> model)
        {
            var response = Response;

            response.Headers.Add(Constants.SharedHttpHeaders.PagingTotal, model.Total.ToString());

            if (model.First.HasValue)
            {
                response.Headers.Add(Constants.SharedHttpHeaders.PagingFirst, model.First.ToString());
            }

            if (model.Last.HasValue)
            {
                response.Headers.Add(Constants.SharedHttpHeaders.PagingLast, model.Last.ToString());
            }
        }
Beispiel #26
0
        public async Task <IActionResult> Index()
        {
            var racingCategory = Server.Instance.Categories.Categories.SingleOrDefault(c => c.Name.Equals("racing", StringComparison.CurrentCultureIgnoreCase));

            if (racingCategory != null)
            {
                ViewData["FeaturedGalleries"] = await Server.Instance.Galleries.GetGalleriesAsync(racingCategory, 1, 3, 3);
            }
            else
            {
                ViewData["FeaturedGalleries"] = new PagedResultSet <Gallery>();
            }

            ViewData["LatestGalleries"] = await Server.Instance.Galleries.GetLatestActiveGalleriesAsync(12);

            return(View());
        }
Beispiel #27
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <PagedResultSet <DomainModel.Subscription> > MySubscriptions(Models.Common.PageDetails pageDetails)
        {
            Expression <Func <DomainModel.Subscription, bool> > expression = subscription => true;

            if (!string.IsNullOrWhiteSpace(pageDetails?.SearchText))
            {
                expression = expression.And(subscription => subscription.Name.Contains(pageDetails.SearchText));
            }

            var subscriptions = await Repository.GetAsync(expression);

            var skip = pageDetails?.PageSize != null && pageDetails?.PageNo != null ?
                       pageDetails.PageSize.Value * (pageDetails.PageNo.Value - 1) :
                       pageDetails?.PageSize;

            return(PagedResultSet <DomainModel.Subscription> .Construct(subscriptions, skip, pageDetails?.PageSize));
        }
        public async Task <PagedResultSet <MovieResponseModel> > GetMoviesByPagination(int pageSize = 20, int page = 0, string title = "")
        {
            Expression <Func <Movie, bool> > filterExpression = null;

            //contains translate translated to sql like
            if (!string.IsNullOrEmpty(title))
            {
                filterExpression = movie => title != null && movie.Title.Contains(title);
            }

            var pagedMovies = await _movieRepository.GetPagedData(page, pageSize, movies => movies.OrderBy(m => m.Title), filterExpression);

            var pagedMovieResponseModel = _mapper.Map <List <MovieResponseModel> >(pagedMovies);

            var movies = new PagedResultSet <MovieResponseModel>(pagedMovieResponseModel, page, pageSize, pagedMovies.TotalCount);

            return(movies);
        }
Beispiel #29
0
        protected override async Task <PagedResultSet <PostView> > HandleInput(FindByValueParams <string> input)
        {
            using (var connection = database.GetConnection()) {
                IPostRepo postRepo = database.GetRepo <IPostRepo>(connection);
                IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection);

                PagedResultSet <Post> posts = await postRepo.FindByUser(input.Value, input.Pagination?.PageNumber ?? 0, input.Pagination?.PageSize ?? Post.PageSize);

                if (input.User != null)
                {
                    foreach (Post p in posts)
                    {
                        p.Vote = await voteRepo.FindByUserAndPost(input.User.Username, p.Id);
                    }
                }

                return(new PagedResultSet <PostView>(posts.Items.Select(p => postMapper.Map(p)), posts.Pagination));
            }
        }
Beispiel #30
0
        public async Task <PagedResultSet <MovieResponseModel> > GetMoviesByPagination(int page = 20, int pageSize = 25, string title = "")
        {
            var movies = await _movieRepository.GetPagedData(page, pageSize);

            var responseMovies = new List <MovieResponseModel>();

            foreach (var item in movies)
            {
                responseMovies.Add(new MovieResponseModel
                {
                    Id          = item.Id,
                    PosterUrl   = item.PosterUrl,
                    ReleaseDate = item.ReleaseDate.Value,
                    Title       = item.Title
                });
            }
            var set = new PagedResultSet <MovieResponseModel>(responseMovies, page, pageSize, movies.Count);

            return(set);
        }