Example #1
0
        public virtual async Task <CustomerAuctionsModel> PrepareAuctions(Customer customer)
        {
            var model          = new CustomerAuctionsModel();
            var priceFormatter = _serviceProvider.GetRequiredService <IPriceFormatter>();

            var customerBids = (await _auctionService.GetBidsByCustomerId(customer.Id)).GroupBy(x => x.ProductId);

            foreach (var item in customerBids)
            {
                var product = await _productService.GetProductById(item.Key);

                if (product != null)
                {
                    var bid = new ProductBidTuple();
                    bid.Ended   = product.AuctionEnded;
                    bid.OrderId = item.Where(x => x.Win && x.CustomerId == customer.Id).FirstOrDefault()?.OrderId;
                    var amount = product.HighestBid;
                    bid.CurrentBidAmount      = priceFormatter.FormatPrice(amount);
                    bid.CurrentBidAmountValue = amount;
                    bid.HighestBidder         = product.HighestBidder == customer.Id;
                    bid.EndBidDate            = product.AvailableEndDateTimeUtc.HasValue ? _dateTimeHelper.ConvertToUserTime(product.AvailableEndDateTimeUtc.Value, DateTimeKind.Utc) : DateTime.MaxValue;
                    bid.ProductName           = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
                    bid.ProductSeName         = product.GetSeName(_workContext.WorkingLanguage.Id);
                    bid.BidAmountValue        = item.Max(x => x.Amount);
                    bid.BidAmount             = priceFormatter.FormatPrice(bid.BidAmountValue);
                    model.ProductBidList.Add(bid);
                }
            }

            model.CustomerId = customer.Id;

            return(model);
        }
Example #2
0
        public virtual CustomerAuctionsModel PrepareAuctions(Customer customer)
        {
            var model          = new CustomerAuctionsModel();
            var priceFormatter = EngineContext.Current.Resolve <IPriceFormatter>();

            var customerBids = _auctionService.GetBidsByCustomerId(customer.Id).GroupBy(x => x.ProductId);

            foreach (var item in customerBids)
            {
                var product = _productService.GetProductById(item.Key);
                if (product != null)
                {
                    var bid = new ProductBidTuple();
                    bid.Ended   = product.AuctionEnded;
                    bid.OrderId = item.Where(x => x.Win && x.CustomerId == customer.Id).FirstOrDefault()?.OrderId;
                    var amount = product.HighestBid;
                    bid.CurrentBidAmount      = priceFormatter.FormatPrice(amount);
                    bid.CurrentBidAmountValue = amount;
                    bid.HighestBidder         = product.HighestBidder == customer.Id;
                    bid.EndBidDate            = product.AvailableEndDateTimeUtc.HasValue ? product.AvailableEndDateTimeUtc.Value : DateTime.MaxValue;
                    bid.ProductName           = product.GetLocalized(x => x.Name);
                    bid.ProductSeName         = product.GetSeName();
                    bid.BidAmountValue        = item.Max(x => x.Amount);
                    bid.BidAmount             = priceFormatter.FormatPrice(bid.BidAmountValue);
                    model.ProductBidList.Add(bid);
                }
            }

            model.CustomerId = customer.Id;

            return(model);
        }