public int CreateOrUpdate(StoreChangeApiModel created, int department, int userId) { var changetype = _storeChangeTypeRespository.GetIndex(created.ChangeTypeId); lock (balance) { var store = _storeRespository.GetIndexByGoods(department, created.HospitalChangeGoods.HospitalGoodId); var afterqty = (store?.Qty ?? 0) + changetype.Operator * created.HospitalChangeGoods.ChangeQty; if (afterqty < 0) { throw new DefaultException("库存不足!"); } return(_storeRespository.CreateOrUpdate(created.HospitalChangeGoods, afterqty, created.ChangeTypeId, department, userId)); } }
public async Task <int> ComfirmAsync(IList <int> ids, int userId) { foreach (var id in ids) { var goods = await _purchaseGoodsBillnoRespository.GetIndexAsync(id); var changed = new StoreChangeApiModel { ChangeTypeId = (int)StoreChangeType.Purchase, HospitalChangeGoods = new StoreChangeGoodsValueModel { HospitalGoodId = goods.HospitalGoods.Id, ChangeQty = goods.Qty, Recrdno = RecordNumber.Next((int)StoreChangeType.Purchase, id), }, }; var recordId = _storeContext.CreateOrUpdate(changed, goods.Purchase.HospitalDepartment.Id, userId); _storeRecordBillnoContext.Create(id, recordId); _purchaseGoodsBillnoRespository.UpdateStatus(id, BillStatus.Comfirmed); } return(ids.Count); }