示例#1
0
        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)
            }));
        }
        internal IResult <IInventoryReturn> Execute(InventoryPredicateBuilder.PredicateBuilderFilters filters, DateTime currentDate)
        {
            var predicateResult = InventoryPredicateBuilder.BuildPredicate(_inventoryUnitOfWork, filters);

            if (!predicateResult.Success)
            {
                return(predicateResult.ConvertTo <IInventoryReturn>());
            }

            var attributes = AttributeNameProjectors.SelectActiveAttributeNames(_inventoryUnitOfWork);
            var inventory  = _inventoryUnitOfWork.InventoryRepository
                             .Filter(predicateResult.ResultingObject)
                             .SplitSelect(InventoryProjectors.SplitSelectInventorySummary(_inventoryUnitOfWork, currentDate));

            var inventoryReturn = new InventoryReturn
            {
                AttributeNamesAndTypes = attributes.ExpandAll().Invoke(),
                Inventory = inventory
            };

            if (!inventoryReturn.Inventory.Any())
            {
                if (filters != null && filters.LotKey != null)
                {
                    var lotKey = new LotKey(filters.LotKey);
                    if (!_inventoryUnitOfWork.OptimizeForReadonly().LotRepository
                        .All()
                        .AsExpandable()
                        .AsNoTracking()
                        .Any(lotKey.FindByPredicate))
                    {
                        return(new InvalidResult <IInventoryReturn>(null, string.Format(UserMessages.LotNotFound, lotKey.KeyValue)));
                    }
                }
            }

            return(new SuccessResult <IInventoryReturn>(inventoryReturn));
        }