internal static Expression <Func <Lot, IQueryable <LotProductionResults> > > SelectChileLotResults(ILotUnitOfWork lotUnitOfWork)
        {
            var results      = lotUnitOfWork.LotProductionResultsRepository.All();
            var lotPredicate = LotPredicates.ConstructLotKeyPredicate <Lot, LotProductionResults>();

            return(lot => results.Where(lotPredicate.Invoke(lot)).Take(1));
        }
        internal static Expression <Func <Lot, IQueryable <PackagingLot> > > SelectPackagingLot(ILotUnitOfWork lotUnitOfWork)
        {
            var packagingLots = lotUnitOfWork.PackagingLotRepository.All();
            var lotPredicate  = LotPredicates.ConstructLotKeyPredicate <Lot, PackagingLot>();

            return(lot => packagingLots.Where(lotPredicate.Invoke(lot)).Take(1));
        }
Exemple #3
0
        public IResult <ILabReportReturn> GetLabReport(DateTime minTestDate, DateTime maxTestDate)
        {
            if (minTestDate > maxTestDate)
            {
                var max = minTestDate;
                minTestDate = maxTestDate;
                maxTestDate = max;
            }

            return(new GetLabReportConductor(_lotUnitOfWork).GetLabReport(LotPredicates.FilterByAttributeDateForLabReport(minTestDate, maxTestDate)));
        }
        internal static IEnumerable <Expression <Func <Lot, LotSummaryReturn> > > SplitSelectLotSummary(ILotUnitOfWork lotUnitOfWork, DateTime currentDate)
        {
            if (lotUnitOfWork == null)
            {
                throw new ArgumentNullException("lotUnitOfWork");
            }

            var attributes = LotAttributeProjectors.Select();
            var lotDefects = LotDefectProjectors.SelectLotDefect();
            var product    = SelectDerivedProduct();
            var loBac      = SelectLoBac();
            var astaCalc   = SelectAstaCalc(lotUnitOfWork, currentDate);

            var customer          = PackScheduleProjectors.SelectCustomerHeader();
            var productionBatches = lotUnitOfWork.ProductionBatchRepository.All();
            var lotKeyFilter      = LotPredicates.ConstructLotKeyPredicate <Lot, ProductionBatch>();

            return(new[]
            {
                SelectLotBase().Merge(l => new LotSummaryReturn
                {
                    LotDateCreated = l.LotDateCreated,
                }).ExpandAll(),

                Projector <Lot> .To(l => new LotSummaryReturn
                {
                    AstaCalcDate = currentDate,
                    Attributes = l.Attributes.Select(a => attributes.Invoke(a)),
                    Defects = l.LotDefects.OrderBy(d => d.DefectId).Select(d => lotDefects.Invoke(d))
                }),

                Projector <Lot> .To(l => new LotSummaryReturn
                {
                    LoBac = loBac.Invoke(l),
                    LotProduct = product.Invoke(l),
                }),

                Projector <Lot> .To(l => new LotSummaryReturn
                {
                    AstaCalc = astaCalc.Invoke(l),
                }),

                Projector <Lot> .To(l => new LotSummaryReturn
                {
                    Customer = productionBatches
                               .Where(lotKeyFilter.Invoke(l))
                               .Select(b => customer.Invoke(b.PackSchedule)).FirstOrDefault()
                })
            });
        }
        internal static Expression <Func <Lot, int?> > SelectAstaCalc(ILotUnitOfWork lotUnitOfWork, DateTime currentDate)
        {
            if (lotUnitOfWork == null)
            {
                throw new ArgumentNullException("lotUnitOfWork");
            }

            var calculateAsta = CalculateAsta(currentDate);
            var results       = lotUnitOfWork.LotProductionResultsRepository.All();
            var lotKeyFilter  = LotPredicates.ConstructLotKeyPredicate <Lot, LotProductionResults>();

            return(Projector <Lot> .To(l => calculateAsta.Invoke
                                       (
                                           l.Attributes.FirstOrDefault(a => a.AttributeShortName == GlobalKeyHelpers.AstaAttributeNameKey.AttributeNameKey_ShortName),
                                           results.Where(lotKeyFilter.Invoke(l)).Select(r => (DateTime?)r.ProductionEnd).FirstOrDefault()
                                       )));
        }
        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));
        }
        protected IResult <Lot> CreateLot(CreateNewLotCommandParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            parameters.LotDate = parameters.LotDate.ToLocalTime().Date; // ensure LotDate is always created in local time

            int newLotSequence;

            if (parameters.LotSequence != null)
            {
                var lot = LotUnitOfWork.LotRepository.Filter(l => l.LotDateCreated == parameters.LotDate && l.LotDateSequence == parameters.LotSequence && l.LotTypeId == (int)parameters.LotType).FirstOrDefault();
                if (lot != null)
                {
                    return(new InvalidResult <Lot>(null, string.Format(UserMessages.LotExistsWithKey, lot.ToLotKey())));
                }

                newLotSequence = (int)parameters.LotSequence;
            }
            else
            {
                newLotSequence = new EFUnitOfWorkHelper(LotUnitOfWork).GetNextSequence(LotPredicates.FilterByLotDateAndTypeId(parameters.LotDate, parameters.LotType), l => l.LotDateSequence);
            }

            if (newLotSequence < 1)
            {
                return(new InvalidResult <Lot>(null, string.Format(UserMessages.LotDateSequenceLessThanOne)));
            }

            var packagingKey = parameters.PackagingReceivedKey;

            if (packagingKey == null)
            {
                packagingKey = LotUnitOfWork.PackagingProductRepository.Filter(p => p.Weight <= 0.0, p => p.Product).ToList().FirstOrDefault(p => p.Product.Name.Replace(" ", "").ToUpper() == "NOPACKAGING");
                if (packagingKey == null)
                {
                    return(new InvalidResult <Lot>(null, UserMessages.NoPackagingNotFound));
                }
            }

            var newLot = LotUnitOfWork.LotRepository.Add(new Lot
            {
                EmployeeId = parameters.EmployeeKey.EmployeeKey_Id,
                TimeStamp  = parameters.TimeStamp,

                LotDateCreated  = parameters.LotDate.Date,
                LotDateSequence = newLotSequence,
                LotTypeEnum     = parameters.LotType,

                ReceivedPackagingProductId = packagingKey.PackagingProductKey_ProductId,

                QualityStatus         = parameters.LotQualityStatus,
                ProductionStatus      = parameters.LotProductionStatus,
                ProductSpecComplete   = parameters.ProductSpecComplete,
                ProductSpecOutOfRange = parameters.ProductSpecOutOfRange,

                VendorId            = parameters.VendorKey == null ? (int?)null : parameters.VendorKey.CompanyKey_Id,
                PurchaseOrderNumber = parameters.PurchaseOrderNumber,
                ShipperNumber       = parameters.ShipperNumber
            });

            return(new SuccessResult <Lot>(newLot));
        }
Exemple #8
0
        internal IResult <LotHistory> Execute(Lot lot, DateTime timestamp)
        {
            var history = _lotUnitOfWork.LotHistoryRepository.Add(new LotHistory
            {
                LotDateCreated  = lot.LotDateCreated,
                LotDateSequence = lot.LotDateSequence,
                LotTypeId       = lot.LotTypeId,
                Sequence        = new EFUnitOfWorkHelper(_lotUnitOfWork).GetNextSequence(LotPredicates.ConstructPredicate <LotHistory>(lot), h => h.Sequence),

                EmployeeId = lot.EmployeeId,
                TimeStamp  = timestamp,

                Serialized = JsonConvert.SerializeObject(new SerializedLotHistory(lot))
            });

            return(new SuccessResult <LotHistory>(history));
        }