public IResult <IQueryable <IInventoryTransactionReturn> > GetInventoryTransactions(string lotKey) { var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <IQueryable <IInventoryTransactionReturn> >()); } var parsedLotKey = lotKeyResult.ResultingObject.ToLotKey(); var predicate = InventoryTransactionPredicates.BySourceLot(parsedLotKey); var select = InventoryTransactionProjectors.Select(_inventoryUnitOfWork); var query = _inventoryUnitOfWork.InventoryTransactionsRepository.Filter(predicate).Select(select); var pickedPredicate = PickedInventoryItemPredicates.FilterByLotKey(parsedLotKey); var pickedSelect = PickedInventoryItemProjectors.SelectTransaction(_inventoryUnitOfWork); var pickedResults = _inventoryUnitOfWork.ProductionBatchRepository .Filter(b => new[] { b.Production.Results }.All(r => r == null)) .AsExpandable() .SelectMany(b => b.Production.PickedInventory.Items .Where(i => pickedPredicate.Invoke(i)) .Select(i => pickedSelect.Invoke(i, b))); var results = query.ToList <IInventoryTransactionReturn>().Concat(pickedResults).AsQueryable(); return(new SuccessResult <IQueryable <IInventoryTransactionReturn> >(results)); }
public IResult <IInventoryTransactionsByLotReturn> GetLotInputTransactions(string lotKey) { var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <IInventoryTransactionsByLotReturn>()); } var parsedLotKey = lotKeyResult.ResultingObject.ToLotKey(); var product = _inventoryUnitOfWork.LotRepository.FilterByKey(parsedLotKey) .Select(LotProjectors.SelectDerivedProduct()) .FirstOrDefault(); var predicate = InventoryTransactionPredicates.ByDestinationLot(parsedLotKey); var select = InventoryTransactionProjectors.Select(_inventoryUnitOfWork); var query = _inventoryUnitOfWork.InventoryTransactionsRepository.Filter(predicate).Select(select).ToList(); var batchPredicate = ProductionBatchPredicates.ByLotKey(parsedLotKey); var pickedSelect = PickedInventoryItemProjectors.SelectTransaction(_inventoryUnitOfWork); var pickedResults = _inventoryUnitOfWork.ProductionBatchRepository .Filter(batchPredicate.And(b => new[] { b.Production.Results }.All(r => r == null))) .AsExpandable() .SelectMany(b => b.Production.PickedInventory.Items.Select(i => pickedSelect.Invoke(i, b))); var results = query.ToList <IInventoryTransactionReturn>().Concat(pickedResults).AsQueryable(); return(new SuccessResult <IInventoryTransactionsByLotReturn>(new InventoryTransactionsByLotReturn { Product = product, InputItems = results })); }
public IResult <IQueryable <IInventoryTransactionReturn> > GetInventoryReceived(GetInventoryReceivedParameters parameters) { var predicate = InventoryTransactionPredicates.ByTransactionType(InventoryTransactionType.ReceiveInventory); if (parameters != null) { if (parameters.LotKey != null) { var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(parameters.LotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <IQueryable <IInventoryTransactionReturn> >()); } predicate = predicate.And(InventoryTransactionPredicates.BySourceLot(lotKeyResult.ResultingObject.ToLotKey())); } else if (parameters.LotType != null) { predicate = predicate.And(InventoryTransactionPredicates.BySourceLotType(parameters.LotType.Value)); } if (parameters.DateReceivedStart != null) { predicate = predicate.And(InventoryTransactionPredicates.ByDateReceivedRangeStart(parameters.DateReceivedStart.Value)); } if (parameters.DateReceivedEnd != null) { predicate = predicate.And(InventoryTransactionPredicates.ByDateReceivedRangeEnd(parameters.DateReceivedEnd.Value)); } } var select = InventoryTransactionProjectors.Select(_inventoryUnitOfWork); var results = _inventoryUnitOfWork.InventoryTransactionsRepository .Filter(predicate) .AsExpandable() .Select(select); return(new SuccessResult <IQueryable <IInventoryTransactionReturn> >(results)); }