/// <summary> /// Get list of products that user is able to bid on /// </summary> /// <param name="userId"></param> /// <returns></returns> public List <ProductBidViewModel> GetCurrentAuctionProducts(int userId) { var currentDateTime = DateTime.Now; var products = Products.Where(p => p.AuctionEndTime > currentDateTime && p.AuctionStartTime <= currentDateTime && p.SellerUserId != userId).ToList(); var bids = _bidService.GetBids(products); var productBidsViewModel = products.Select(p => new ProductBidViewModel { ProductId = p.Id, Name = p.Name, AuctionEndDate = p.AuctionEndTime, Description = p.Description, StartPrice = p.StartPrice, SellerId = p.SellerUserId, SellerName = "Jane" //todo create service to get username by Id }).ToList(); for (int i = 0; i < productBidsViewModel.Count(); i++) { var currentBid = bids.Where(b => b.ProductId == productBidsViewModel[i].ProductId).OrderByDescending(b => b.BidDateTime).FirstOrDefault(); productBidsViewModel[i].CurrentPrice = currentBid != null ? currentBid.BidAmount : productBidsViewModel[i].StartPrice; } return(productBidsViewModel); }
public ActionResult Index() { var id = HttpContext.User.Identity.GetUserId(); var bidDTOs = bidService.GetBids(); var bidModels = Mapper.Map <IEnumerable <BidDTO>, ICollection <BiddingModel> >(bidDTOs) .Where(x => x.UserId == id) .ToList(); return(View(bidModels)); }
public ActionResult Index(BidIndexOptions options, PagerParameters pagerParameters) { var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); // Default options if (options == null) { options = new BidIndexOptions(); } // Filtering IContentQuery <BidPart, BidPartRecord> bidsQuery; switch (options.Filter) { case BidIndexFilter.All: bidsQuery = _bidService.GetBids(); break; default: throw new ArgumentOutOfRangeException(); } var pagerShape = Shape.Pager(pager).TotalItemCount(bidsQuery.Count()); var entries = bidsQuery .OrderByDescending <BidPartRecord>(b => b.BidedOn) .Slice(pager.GetStartIndex(), pager.PageSize) .ToList() .Select(CreateBidEntry); var model = new BidsIndexViewModel { Bids = entries.ToList(), Options = options, Pager = pagerShape }; return(View(model)); }