public IResult <ILotQualitySingleSummaryReturn> GetLot(string lotKey) { if (lotKey == null) { throw new ArgumentNullException("lotKey"); } var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <ILotQualitySingleSummaryReturn>()); } var predicate = new LotKey(lotKeyResult.ResultingObject).FindByPredicate; var select = LotProjectors.SplitSelectSingleLotSummary(_lotUnitOfWork, _timeStamper.CurrentTimeStamp); var lotSummary = _lotUnitOfWork.LotRepository .Filter(predicate) .SplitSelect(select) .ToList().SingleOrDefault(); if (lotSummary == null) { return(new InvalidResult <ILotQualitySingleSummaryReturn>(null, string.Format(UserMessages.LotNotFound, lotKey))); } return(new SuccessResult <ILotQualitySingleSummaryReturn>(lotSummary)); }
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 static Expression <Func <Lot, bool> > FilterByProductKey(ILotUnitOfWork lotUnitOfWork, IKey <Product> productKey) { var productPredicate = productKey.FindByPredicate; var product = LotProjectors.SelectProduct(lotUnitOfWork); return(l => productPredicate.Invoke(product.Invoke(l))); }
internal static Expression <Func <Lot, bool> > FilterByProductType(ILotUnitOfWork lotUnitOfWork, ProductTypeEnum productType) { if (lotUnitOfWork == null) { throw new ArgumentNullException("lotUnitOfWork"); } var product = LotProjectors.SelectProduct(lotUnitOfWork); return(l => product.Invoke(l).ProductType == productType); }
internal static Expression <Func <Lot, bool> > FilterByLotProductionStart(ILotUnitOfWork lotUnitOfWork, DateTime?rangeStart, DateTime?rangeEnd) { if (lotUnitOfWork == null) { throw new ArgumentNullException("lotUnitOfWork"); } var results = LotProjectors.SelectChileLotResults(lotUnitOfWork); var byProductionBegin = ProductionResultPredicates.FilterByProductionBegin(rangeStart, rangeEnd); return(l => results.Invoke(l).Select(r => byProductionBegin.Invoke(r)).FirstOrDefault() ?? false); }
private static Expression <Func <Inventory, bool> > ValidForTreatmentOrder(IInventoryTreatmentKey treatment, ITreatmentOrderUnitOfWork unitOfWork) { var lotsAreEqual = LotProjectors.SelectLotsAreEqual(); var validTreatment = treatment.ToInventoryTreatmentKey().FindByPredicate .Or(Data.Models.StaticRecords.StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey().FindByPredicate); var treatmentOrders = unitOfWork.TreatmentOrderRepository.All(); var lots = unitOfWork.LotRepository.All(); return(i => lots .Where(l => lotsAreEqual.Invoke(i.Lot, l)) .SelectMany(l => l.Inventory.Select(n => n.Treatment).Concat(l.PickedInventory.Select(p => p.Treatment))) .Concat(treatmentOrders .Where(o => o.InventoryShipmentOrder.OrderStatus != OrderStatus.Void && o.InventoryShipmentOrder.PickedInventory.Items.Any(l => lotsAreEqual.Invoke(l.Lot, i.Lot))) .Select(o => o.Treatment)) .All(t => validTreatment.Invoke(t))); }
internal IResult <ILabReportReturn> GetLabReport(Expression <Func <ChileLot, bool> > lotPredicate) { var context = ((EFUnitOfWorkBase)_lotUnitOfWork).Context; var adapter = context as IObjectContextAdapter; adapter.ObjectContext.CommandTimeout = 600; if (lotPredicate == null) { throw new ArgumentNullException("lotPredicate"); } var select = LotProjectors.SelectLabReportChileLot(_lotUnitOfWork.ProductionBatchRepository.All(), _lotUnitOfWork.LotProductionResultsRepository.All(), _lotUnitOfWork.ChileLotProductionRepository.All()); var predicate = lotPredicate.And(LotPredicates.FilterForLabReport()).ExpandAll(); var chileLots = _lotUnitOfWork.ChileLotRepository .Filter(predicate) .SplitSelect(select) .ToList(); return(CreateLabReport(chileLots)); }
public IResult <ILotQualitySummariesReturn> GetLots(FilterLotParameters parameters) { var predicateResult = LotPredicateBuilder.BuildPredicate(_lotUnitOfWork, parameters); if (!predicateResult.Success) { return(predicateResult.ConvertTo <ILotQualitySummariesReturn>()); } var selectAttributes = AttributeNameProjectors.SelectActiveAttributeNames(_lotUnitOfWork); var selectLotSummary = LotProjectors.SplitSelectLotQualitySummary(_lotUnitOfWork, _timeStamper.CurrentTimeStamp); return(new SuccessResult <ILotQualitySummariesReturn>(new LotSummariesReturn { AttributeNamesAndTypes = selectAttributes.ExpandAll().Invoke().ToList(), LotSummaries = _lotUnitOfWork.LotRepository .Filter(predicateResult.ResultingObject) .OrderByLot() .SplitSelect(selectLotSummary) })); }
public IResult <ILotHistoryReturn> GetLotHistory(string lotKey) { var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <ILotHistoryReturn>()); } var parsedLotKey = lotKeyResult.ResultingObject.ToLotKey(); var result = _lotUnitOfWork.LotRepository .FilterByKey(parsedLotKey) .SplitSelect(LotProjectors.SplitSelectHistory()) .FirstOrDefault(); if (result == null) { return(new InvalidResult <ILotHistoryReturn>(null, string.Format(UserMessages.LotNotFound, parsedLotKey))); } return(new SuccessResult <ILotHistoryReturn>(result)); }
internal LotTraceOutputCommand(ILotUnitOfWork lotUnitOfWork) { _lotUnitOfWork = lotUnitOfWork; _selectOutputs = LotProjectors.SelectLotOutputTrace(lotUnitOfWork); }