Ejemplo n.º 1
0
        /// <summary>
        /// Starts new trade
        /// </summary>
        /// <param name="newTrade">Trade to start</param>
        public void StartTrade(NewTradeDTO newTrade)
        {
            if (!LotService.IsLotExists(newTrade.LotId))
            {
                throw new NotFoundException();
            }
            try
            {
                if (IsTradeForLotAlreadyStarted(newTrade.LotId))
                {
                    throw new AuctionException($"Trade for this lot has already began");
                }

                var lot = Database.TradingLots.GetTradingLotById(newTrade.LotId);

                Database.Trades.AddTrade(new Trade
                {
                    LotId      = newTrade.LotId,
                    TradingLot = lot,
                    TradeStart = DateTime.Now,
                    TradeEnd   = DateTime.Now.AddDays(newTrade.TradeDuration)
                });
                Database.Save();
            }
            catch (AuctionException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new DatabaseException();
            }
        }
Ejemplo n.º 2
0
 public IHttpActionResult StartTrade(NewTradeDTO tradeModel)
 {
     try
     {
         tradeService.StartTrade(tradeModel);
         return(Ok());
     }
     catch (DatabaseException)
     {
         return(StatusCode(HttpStatusCode.InternalServerError));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (AuctionException ex)
     {
         return(BadRequest(ex.Message));
     }
 }