Пример #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);
        }
 public IActionResult AddUnits([FromBody] ProductAddUnitsDto productAddUnitsDto)
 {
     return(Ok(_productRepository.AddUnits(productAddUnitsDto)));
 }