public static void AddTradingRecord(TradingRecord tradingRecord)//ex DataException { using (StockMonitorEntities _dbContext = new StockMonitorEntities()) { _dbContext.TradingRecords.Add(tradingRecord); _dbContext.SaveChanges();//ex DataException } }
public static void DeleteReservedTrading(ReservedTrading reservedTrading)//ex DataException,InvalidOperationException { using (StockMonitorEntities _dbContext = new StockMonitorEntities()) { ReservedTrading trading = _dbContext.ReservedTradings.Find(reservedTrading.Id);//ex InvalidOperationException if (trading == null) { throw new InvalidOperationException($"Cannot find reservedTrading[{reservedTrading.Id}]"); } _dbContext.ReservedTradings.Remove(trading); _dbContext.SaveChanges();//ex DataException,InvalidOperationException } }
public static void DeleteTradingRecord(TradingRecord tradingRecord) {//ex DataException,InvalidOperationException StockMonitorEntities _dbContext = new StockMonitorEntities(); TradingRecord trading = _dbContext.TradingRecords.Find(tradingRecord.Id);//ex InvalidOperationException if (trading == null) { throw new InvalidOperationException($"Cannot find TradingRecord[{tradingRecord.Id}]"); } _dbContext.TradingRecords.Remove(trading); _dbContext.SaveChanges();//ex DataException,InvalidOperationException }
public static void InsertReservedTrading(ReservedTrading reservedTrading) {//ex DateException, InvalidOperationException using (StockMonitorEntities _dbContext = new StockMonitorEntities()) { var companyTrading = from trade in GetReservedTradingList(reservedTrading.UserId) //ex InvalidOperationException where trade.CompanyId == reservedTrading.CompanyId select trade; if (companyTrading.Count() == 0) { _dbContext.ReservedTradings.Add(reservedTrading); _dbContext.SaveChanges(); //ex DataException } else { throw new InvalidOperationException("One Trade reserved already with this company"); } } }