示例#1
0
        /// <summary>
        /// value to add Available Pieces This can be a negative number
        /// </summary>
        /// <param name="id">product id</param>
        /// <param name="value">value to add This can be a negative number</param>
        /// <returns></returns>
        public async Task <bool> AddAvailablePieces(int id, int value)
        {
            var DBProduct = await _context.Products.FindAsync(id);

            _piecesAvailableService.AddPieces(DBProduct, value, _context);
            DBProduct.Updated = DateTime.UtcNow;

            await _context.SaveChangesAsync();

            return(true);
        }
示例#2
0
 private async Task CheckIfInStockAndSetAvailablePieces(Order order, List <Product> products)
 {
     foreach (var item in order.OrderItems)
     {
         Product product = products.FirstOrDefault(p => p.Id == item.ProductId);
         if (product == null)
         {
             throw new BadRequestException(Enum.InternalCode.NotFound, $"productId {item.ProductId} not found.");
         }
         _productPiecesAvailableService.AddPieces(product, item.Quantity * -1, db);
     }
 }