public async Task <ReturnData <bool> > EditAsync(int id, EditStockDto model) { var result = new ReturnData <bool>(); var stock = await _context.Stocks.FirstOrDefaultAsync(i => i.Id == id); if (stock != null) { if (model.InOrOut == InAndOutStockType.In) { stock.Number += model.Number; _context.InAndOutStockDetaileds.Add(new InAndOutStockDetailed { InAndOutStockType = Model.Enums.InAndOutStockType.In, Number = model.Number, StockId = stock.Id, SurplusStock = stock.Number }); } if (model.InOrOut == InAndOutStockType.Out) { if (stock.Number - model.Number < 0) { result.Message = "库存不足,操作失败"; result.Result = false; return(result); } stock.Number -= model.Number; _context.InAndOutStockDetaileds.Add(new InAndOutStockDetailed { InAndOutStockType = Model.Enums.InAndOutStockType.Out, Number = model.Number, StockId = stock.Id, SurplusStock = stock.Number }); } } result.Result = await _context.SaveChangesAsync() > 0; return(result); }
public async Task <IActionResult> InAndOut(EditStockDto model, int id) { var result = await _service.EditAsync(id, model); return(Ok(result)); }