public int Consume(string partNumber, int shopfloorlineId, int qty, string source, string lotId) { var part = m_repo.Get <Part>(p => p.PartNumber == partNumber); var sfl = m_repo.Get <Shopfloorline>(s => s.Id == shopfloorlineId); Transaction trans; var item = MaterialRepository.GetConsumableItemByPart(m_unitOfWork, part, sfl); try { item.ThrowIfNull(partNumber + " was not found in consumable inventory."); item.DecreaseQty(qty); trans = MaterialService.WriteConsumptionTransaction(item, qty, source + " material consumed.", lotId); m_unitOfWork.OnLockingException += (s, e) => { m_unitOfWork.ReloadChangedObjects(); Consume(partNumber, shopfloorlineId, qty, source, lotId); }; m_unitOfWork.Commit(); } catch (Exception ex) { Scout.Core.UserInteraction.Dialog.ShowMessage(ex.Message, UserMessageType.Error); return(default(int)); } return(trans.TransId); }
public MaterialConsumableItem DecreaseItemQty(Part part, Shopfloorline sfl, int qty) { MaterialConsumableItem item = null; Expression <Func <MaterialConsumableItem, bool> > criteria = mci => mci.Part.Id == part.Id && mci.Shopfloorline.Id == sfl.Id && mci.Qty > 0; ExecutionHelpers.ThrowIfNull( () => item = m_repository.Get(criteria), "Consumable item not found" ); item.DecreaseQty(qty); return(item); }