예제 #1
0
		public Task<IPagedList<Auction>> GetAllActiveAuctions(string titleFilter,
		                                                      AuctionSortOrder sortBy,
		                                                      int pageIndex,
		                                                      int auctionsPerPage)
		{
			return GetAuctions(cat => cat.ParentId == null, titleFilter, sortBy, pageIndex, auctionsPerPage);
		}
예제 #2
0
		public Task<IPagedList<Auction>> GetActiveAuctionsInCategory(int categoryId,
		                                                             string titleFilter,
		                                                             AuctionSortOrder sortBy,
		                                                             int pageIndex,
		                                                             int auctionsPerPage)
		{
			return GetAuctions(cat => cat.Id == categoryId, titleFilter, sortBy, pageIndex, auctionsPerPage);
		}
예제 #3
0
		private void InitializeAuctionListingParameters(ref int? pageSize, ref AuctionSortOrder? sortOrder)
		{
			mResponse.SaveToCookieIfNotNull(COOKIE_PAGE_SIZE_KEY,  pageSize);
			mResponse.SaveToCookieIfNotNull(COOKIE_SORT_ORDER_KEY, sortOrder);

			pageSize  = pageSize  ?? mRequest.ReadIntFromCookie(COOKIE_PAGE_SIZE_KEY)                     ?? 20;
			sortOrder = sortOrder ?? mRequest.ReadEnumFromCookie<AuctionSortOrder>(COOKIE_SORT_ORDER_KEY) ?? AuctionSortOrder.EndDateAscending;

			pageSize  = Math.Min(pageSize.Value, 50);
		}
예제 #4
0
		public async Task<ActionResult> All(string searchString = null, AuctionSortOrder? sortOrder = null, int page = 1,
		                                    int? pageSize = null)
		{
			InitializeAuctionListingParameters(ref pageSize, ref sortOrder);

			var auctions  = await mAuctionService.GetAllActiveAuctions(searchString, sortOrder.Value, page, pageSize.Value);				
			var viewModel = CategoryIndexViewModelMapper.FromAuctions(auctions, currentSortOrder: sortOrder.Value);

			return View("Index", viewModel);
		}
        Task<IPagedList<Auction>> IAuctionService.GetAllActiveAuctions(string titleFilter,
		                                                               AuctionSortOrder sortBy,
		                                                               int pageIndex,
		                                                               int auctionsPerPage)
        {
            Contract.Requires(pageIndex >= 1);
            Contract.Requires(auctionsPerPage >= 1);

            throw new NotImplementedException();
        }
예제 #6
0
		public async Task<ActionResult> Index(int id, string searchString = null, AuctionSortOrder? sortOrder = null,
		                                      int page = 1, int? pageSize = null)
		{
			InitializeAuctionListingParameters(ref pageSize, ref sortOrder);

			var auctions  = await mAuctionService.GetActiveAuctionsInCategory(id, searchString, sortOrder.Value, page,
			                                                                  pageSize.Value);
			var viewModel = CategoryIndexViewModelMapper.FromAuctions(auctions, sortOrder.Value, categoryId: id);

			return View(viewModel);
		}
예제 #7
0
		public Task<IPagedList<Auction>> GetAuctions(Expression<Func<Category, bool>> rootCategoryFilter,
		                                             string titleFilter,
		                                             AuctionSortOrder sortBy,
		                                             int pageIndex,
		                                             int auctionsPerPage)
		{
			var auctions = from auction      in mContext.Auctions.Where(AuctionStatusFilter.Active)
			               from rootCategory in mContext.Categories.Where(rootCategoryFilter)

			               from subCategory  in mContext.Categories
			               where subCategory.Left  >= rootCategory.Left &&
			                     subCategory.Right <= rootCategory.Right

			               where auction.CategoryId == subCategory.Id
			               select auction;

			if(!String.IsNullOrWhiteSpace(titleFilter))
			{
				auctions = auctions.Where(x => x.Title.Contains(titleFilter));
			}

			switch(sortBy)
			{
				case AuctionSortOrder.TitleAscending:
					auctions = auctions.OrderBy(x => x.Title);
					break;
				case AuctionSortOrder.TitleDescending:
					auctions = auctions.OrderByDescending(x => x.Title);
					break;

				default: // AuctionSortOrder.EndDateAscending
					auctions = auctions.OrderBy(x => x.EndDate);
					break;
				case AuctionSortOrder.EndDateDescending:
					auctions = auctions.OrderByDescending(x => x.EndDate);
					break;

				case AuctionSortOrder.PriceAscending:
					// TODO sorting should take into account relative value of currencies
					auctions = auctions.OrderByMinimumPrice();
					break;
				case AuctionSortOrder.PriceDescending:
					auctions = auctions.OrderByMinimumPriceDescending();
					break;
			}

			auctions = auctions.Include(x => x.MinimumPrice.Currency)
			                   .Include(x => x.BuyoutPrice.Currency)
			                   .Include(x => x.Offers);

			return Task.FromResult(auctions.ToPagedList(pageIndex, auctionsPerPage));
		}
		public static CategoryIndexViewModel FromAuctions(IPagedList<Auction> auctions,
		                                                  AuctionSortOrder currentSortOrder,
		                                                  int? categoryId = null)
		{
			Contract.Requires(auctions != null);

			return new CategoryIndexViewModel
			{
				CategoryId       = categoryId,
				Auctions         = new StaticPagedList<AuctionViewModel>(auctions.Select(AuctionViewModelMapper.FromAuction),
				                                                         auctions),
				CurrentSortOrder = currentSortOrder,
			};
		}