コード例 #1
0
        public bool AddUnits(ProductAddUnitsDto productAddUnitsDto)
        {
            var last = _context.StockHistories
                       .OrderByDescending(history => history.Created)
                       .FirstOrDefault(history => history.ProductId == productAddUnitsDto.ProductId);

            _context.StockHistories.Add(new StockHistory
            {
                Created       = DateTime.Now,
                Quantity      = productAddUnitsDto.Units,
                Total         = productAddUnitsDto.UnitPrice + productAddUnitsDto.Units,
                Type          = "IN",
                ProductId     = productAddUnitsDto.ProductId,
                TotalQuantity = Convert.ToInt16(productAddUnitsDto.Units + (last?.TotalQuantity ?? 0)),
                UnitPrice     = productAddUnitsDto.UnitPrice
            });
            _context.SaveChanges();
            return(true);
        }
コード例 #2
0
 public IActionResult AddUnits([FromBody] ProductAddUnitsDto productAddUnitsDto)
 {
     return(Ok(_productRepository.AddUnits(productAddUnitsDto)));
 }