Пример #1
0
        public PagedSearchResponseDto <List <PersonSearchResultDto> > SearchPeople(PagedSearchDto dto)
        {
            using (MyDbContext context = new MyDbContext())
            {
                SqlParameter pageSize = new SqlParameter("@PageSize", dto.PageSize ?? (object)DBNull.Value)
                {
                    DbType = System.Data.DbType.Int32
                };
                SqlParameter pageNumber = new SqlParameter("@PageNumber", dto.PageNumber ?? (object)DBNull.Value)
                {
                    DbType = System.Data.DbType.Int32
                };
                SqlParameter orderBy   = new SqlParameter("@OrderBy", string.IsNullOrEmpty(dto.OrderByColumn) ? (object)DBNull.Value : dto.OrderByColumn);
                SqlParameter orderAsc  = new SqlParameter("@OrderAsc", dto.OrderAscending ?? (object)DBNull.Value);
                SqlParameter totalRows = new SqlParameter("@TotalRows", 0)
                {
                    DbType    = System.Data.DbType.Int32,
                    Direction = System.Data.ParameterDirection.Output
                };

                List <PersonSearchResultDto> results = context.Database.SqlQuery <PersonSearchResultDto>("EXEC dbo.GetPeople @PageSize, @PageNumber, @OrderBy, @OrderAsc, @TotalRows OUTPUT",
                                                                                                         pageSize, pageNumber, orderBy, orderAsc, totalRows).ToList();

                PagedSearchResponseDto <List <PersonSearchResultDto> > response = new PagedSearchResponseDto <List <PersonSearchResultDto> >
                {
                    PageSize       = dto.PageSize,
                    PageNumber     = dto.PageNumber,
                    OrderByColumn  = dto.OrderByColumn,
                    OrderAscending = dto.OrderAscending,
                    TotalRows      = (int?)totalRows.Value,
                    Result         = results
                };
                return(response);
            }
        }
Пример #2
0
 public IHttpActionResult SearchPeople(PagedSearchDto dto)
 {
     using (ApiSampleRepository rep = new ApiSampleRepository())
     {
         var results = rep.SearchPeople(dto);
         return(Ok(results));
     }
 }
Пример #3
0
        public async Task MyTestMethod()
        {
            PagedSearchDto dto = new PagedSearchDto();

            dto.PageSize       = 25;
            dto.PageNumber     = 2;
            dto.OrderByColumn  = "FirstName";
            dto.OrderAscending = true;
            dto.TotalRows      = 0;
            ApiResponse response = await _Client.GetPeople(dto);

            PagedSearchResponseDto <List <PersonSearchResultDto> > data = response.GetTypedContent <PagedSearchResponseDto <List <PersonSearchResultDto> > >();

            Assert.AreEqual(dto.PageSize, data.Result.Count);
        }
Пример #4
0
 public void TestGetPeopleWithDefaults()
 {
     using (ApiSampleRepository repository = new ApiSampleRepository())
     {
         PagedSearchDto dto = new PagedSearchDto();
         dto.PageSize       = 25;
         dto.PageNumber     = 2;
         dto.OrderByColumn  = "PersonId";
         dto.OrderAscending = true;
         dto.TotalRows      = 0;
         PagedSearchResponseDto <List <PersonSearchResultDto> > response = repository.SearchPeople(dto);
         Assert.IsTrue(response.Result.Count == 25);
         Assert.IsTrue(response.Result.First().PersonId == 26);
     }
 }
Пример #5
0
        public async Task <PagedResultDto <AuctionListDto> > ListActiveAuction(PagedSearchDto input)
        {
            DateTime now = DateTime.UtcNow;
            IQueryable <Domain.Auction.Auction> auctions = (await _auctionManager
                                                            .GetAll())
                                                           .Where(s => s.EndDate > now)
                                                           .Where(s => s.StartDate < now)
                                                           .WhereIf(!input.Keyword.IsNullOrEmpty(), s => s.Product.Name.Contains(input.Keyword))
                                                           .OrderByDescending(s => s.EndDate);

            if (input.CategoryIds?.Length > 0)
            {
                auctions = auctions.WhereIf(
                    input.CategoryIds?.Length > 0,
                    s => s.Product.ProductCategories
                    .Any(i => input.CategoryIds.Contains(i.CategoryId)));
            }

            auctions = auctions.WhereIf(
                input.BrandId.HasValue,
                s => s.Product.BrandId == input.BrandId);

            auctions = auctions.WhereIf(
                input.MinPrice.HasValue,
                s => s.CurrentPrice >= input.MinPrice);

            auctions = auctions.WhereIf(
                input.MaxPrice.HasValue,
                s => s.CurrentPrice <= input.MaxPrice);

            auctions = auctions.WhereIf(
                input.SellerId.HasValue,
                s => s.SellerId == input.SellerId);

            IQueryable <AuctionListDto> results = auctions.Select(s => new AuctionListDto
            {
                StartTime    = s.StartDate,
                Id           = s.Id,
                ProductName  = s.Product.Name,
                EndTime      = s.EndDate,
                ProductImage = s.Product.CoverImage.Image.Url,
                CurrentPrice = s.CurrentPrice,
                NumberOfBid  = s.NumberOfBid
            });

            return(await GetPagedResult <AuctionListDto>(results, input));
        }
Пример #6
0
        public async Task <ApiResponse> GetPeople(PagedSearchDto dto)
        {
            var uri = BuildUri($"Values/Person/Search");

            return(await PostResultAsync <PagedSearchDto>(uri, dto));
        }