Exemplo n.º 1
0
        private IQueryable <ProductionOrder> ApplyOrder(IQueryable <ProductionOrder> queryProducts,
                                                        ProductionOrderFields orderField, OrderEnum order)
        {
            switch (orderField)
            {
            case ProductionOrderFields.currentStatus:
                if (order == OrderEnum.Ascending)
                {
                    queryProducts = queryProducts.OrderBy(x => x.currentStatus);
                }
                else
                {
                    queryProducts = queryProducts.OrderByDescending(x => x.currentStatus);
                }
                break;

            case ProductionOrderFields.productionOrderNumber:
                if (order == OrderEnum.Ascending)
                {
                    queryProducts = queryProducts.OrderBy(x => x.productionOrderNumber);
                }
                else
                {
                    queryProducts = queryProducts.OrderByDescending(x => x.productionOrderNumber);
                }
                break;

            default:
                queryProducts = queryProducts
                                .OrderByDescending(x => x.latestUpdate)
                                .ThenBy(x => x.productionOrderNumber);
                break;
            }
            return(queryProducts);
        }
Exemplo n.º 2
0
        private IQueryable <ProductionOrder> ApplyFilter(IQueryable <ProductionOrder> queryProducts,
                                                         ProductionOrderFields fieldFilter, string fieldValue)
        {
            switch (fieldFilter)
            {
            case ProductionOrderFields.currentStatus:
                queryProducts = queryProducts.Where(x => x.currentStatus.Contains(fieldValue));
                break;

            case ProductionOrderFields.productionOrderNumber:
                queryProducts = queryProducts.Where(x => x.productionOrderNumber.Contains(fieldValue));
                break;

            case ProductionOrderFields.productionOrderTypeId:
                queryProducts = queryProducts.Where(x => x.productionOrderTypeId.ToString().Contains(fieldValue));
                break;

            case ProductionOrderFields.productionOrderRecipeCode:
                queryProducts = queryProducts.Where(x => x.recipe.recipeCode.ToString().Contains(fieldValue));
                break;

            default:
                break;
            }
            return(queryProducts);
        }
Exemplo n.º 3
0
        public async Task <(List <ProductionOrder>, int)> getProductionOrders(int startat, int quantity
                                                                              , List <string> fields, ProductionOrderFields orderField, OrderEnum order)
        {
            var productionOrdersQuery = _context.ProductionOrders
                                        .Where(x => x.currentStatus != stateEnum.inactive.ToString())
                                        .OrderByDescending(x => x.latestUpdate).AsQueryable();

            foreach (var field in fields)
            {
                string fieldValue = string.Empty;
                var    fieldSplit = field.Split(",");
                if (fieldSplit.Count() > 1)
                {
                    fieldValue = fieldSplit[1];
                }

                var fieldFilterEnum = ProductionOrderFields.Default;
                Enum.TryParse(fieldSplit[0], true, out fieldFilterEnum);
                productionOrdersQuery = ApplyFilter(productionOrdersQuery, fieldFilterEnum, fieldValue);
            }

            productionOrdersQuery = ApplyOrder(productionOrdersQuery, orderField, order);

            var productionOrders = await productionOrdersQuery.Skip(startat).Take(quantity)
                                   .ToListAsync();

            var queryCount = _context.ProductionOrders.Where(x => x.currentStatus != stateEnum.inactive.ToString());

            foreach (var field in fields)
            {
                string fieldValue = string.Empty;
                var    fieldSplit = field.Split(",");
                if (fieldSplit.Count() > 1)
                {
                    fieldValue = fieldSplit[1];
                }

                var fieldFilterEnum = ProductionOrderFields.Default;
                Enum.TryParse(fieldSplit[0], true, out fieldFilterEnum);
                queryCount = ApplyFilter(queryCount, fieldFilterEnum, fieldValue);
            }
            queryCount = ApplyOrder(queryCount, orderField, order);
            var totalCount = queryCount.Count();
            List <ProductionOrder> result = new List <ProductionOrder>();

            foreach (var item in productionOrders)
            {
                result.Add(await getProductionOrder(item.productionOrderId));
            }

            return(result, totalCount);
        }