示例#1
0
        public async Task AddAsync(Stock stock)
        {
            long nFound = await dbContext.StockCollection.CountDocumentsAsync(stockDoc => stockDoc.Code == stock.Code);

            if (nFound > 0)
            {
                throw new AlreadyInDbException();
            }
            StockDocument stockDoc = mapper.Map <StockDocument>(stock);
            await dbContext.StockCollection.InsertOneAsync(stockDoc);
        }
示例#2
0
        public async Task UpdateAsync(Stock stock)
        {
            long nFound = await dbContext.StockCollection.CountDocumentsAsync(stockDoc => stockDoc.Code == stock.Code);

            if (nFound <= 0)
            {
                throw new NotFoundInDbException();
            }
            StockDocument newStockDoc = mapper.Map <StockDocument>(stock);
            await dbContext.StockCollection.ReplaceOneAsync(stockDoc => stockDoc.Code == stock.Code, newStockDoc);
        }
示例#3
0
 public async Task <Stock> GetOneAsync(string code)
 {
     using (IAsyncCursor <StockDocument> query = await dbContext.StockCollection.FindAsync(stockDoc => stockDoc.Code == code))
     {
         if (query == null)
         {
             throw new NotFoundInDbException();
         }
         StockDocument stockDoc = query.FirstOrDefault();
         if (stockDoc == null)
         {
             throw new NotFoundInDbException();
         }
         return(mapper.Map <Stock>(stockDoc));
     }
 }