/// <summary>
        /// Update auction info
        /// </summary>
        /// <param name="e">Auction to update</param>
        public async Task Update(BllAuction e)
        {
            if (e == null || e.Lot == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            await Update(e.Lot);
        }
        async Task <IEnumerable <BllAuction> > IService <BllAuction, int> .GetAll()
        {
            var lots = await GetAll();

            var auctions = new BllAuction[lots.Count()];
            IEnumerator <BllLot> enumerator = lots.GetEnumerator();

            for (int i = 0; i < auctions.Length; i++)
            {
                auctions[i] = new BllAuction()
                {
                    Lot = enumerator.Current
                };
                enumerator.MoveNext();
            }
            return(auctions);
        }
        /// <summary>
        /// Combining lot info, bids and comments into one object
        /// </summary>
        /// <param name="id">Id of a lot</param>
        /// <param name="take">Number of comments to take</param>
        /// <returns>Total info about auction</returns>
        public async Task <BllAuction> GetTotalAuctionInfo(int id, int take)
        {
            if (id < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            var auction = new BllAuction();

            auction.Lot  = (await Context.LotsRepository.GetById(id)).ToBllLot();
            auction.Bids = (await Context.BidsRepository.FindLotBids(id)).Select(t => t.ToBllBid());
            if (take > 0)
            {
                auction.Comments = (await Context.CommentsRepository.FindAllLotComments(id)).OrderByDescending(t => t.Date).Take(take).Select(t => t.ToBllComment());
            }
            else
            {
                auction.Comments = (await Context.CommentsRepository.FindAllLotComments(id)).OrderByDescending(t => t.Date).Select(t => t.ToBllComment());
            }
            return(auction);
        }
        /// <summary>
        /// Delete all info about auction (inc. comments, bids)
        /// </summary>
        /// <param name="e">Auction to delete</param>
        public async Task Delete(BllAuction e)
        {
            if (e == null || e.Lot == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            if (e.Comments != null)
            {
                await Context.CommentsRepository.DeleteRange(e.Comments.Select(t => t.ToDalCommentary()));
            }
            if (e.Bids != null)
            {
                await Context.BidsRepository.DeleteRange(e.Bids.Select(t => t.ToDalBid()));
            }
            if (e.Lot != null)
            {
                await Context.LotsRepository.Delete(e.Lot.ToDalLot());
            }
            Context.Commit();
        }
        public static AuctionDetail ToMvcAuctionDetail(this BllAuction auction, IUserService userService)
        {
            var returnValue = new AuctionDetail()
            {
                AuctionEndDate = auction.Lot.AuctionEndDate,
                CreationDate   = auction.Lot.CreationDate,
                CurrentPrice   = auction.Lot.CurrentPrice,
                Description    = auction.Lot.Description,
                LastUpdateDate = auction.Lot.LastUpdateDate,
                Id             = auction.Lot.Id,
                Photos         = auction.Lot?.Photos?.Split(':') ?? Enumerable.Empty <string>(),
                SellerId       = auction.Lot.Seller,
                Title          = auction.Lot.Title,
                Bids           = auction?.Bids.Select(t => t.ToMvcBid(userService)),
                Comments       = auction?.Comments.Select(t => t.ToMvcComment(userService))
            };

            Task <BllUser> task = Task.Run(() => userService.GetById(auction.Lot.Seller));

            task.Wait();
            returnValue.Seller = task.Result.Login;
            return(returnValue);
        }
 /// <summary>
 /// Create lot
 /// </summary>
 /// <param name="e">Lot to create</param>
 /// <returns>Id of the created lot</returns>
 async Task <int> IService <BllAuction, int> .Create(BllAuction e)
 {
     return(await Create(e.Lot));
 }