/// <summary> /// Gets the lot with bids checking the state and time left. /// Actually the lot selling occures here by marking the lot as sold. /// </summary> /// <param name="id"></param> /// <returns> /// Lot domain object. /// </returns> public async Task <Lot> GetLotWithBidsAsync(int id) { var lot = await _lotRepository.GetLotWithBidsAsync(id); if (lot == null) { throw new LotNotFoundException(id); } var activeLotState = await _lotStateRepository.GetStateByNameAsync("Active"); // The second check is for preventing double marking sold lot. if (DateTime.Now > lot.EndTime && lot.LotStateID == activeLotState.LotStateID) { await MarkLotAsSold(lot); await _unitOfWork.CompleteAsync(); } return(lot); }