Exemplo n.º 1
0
        private async Task <ProductTraceability> AddInDB(ProductTraceability product, InputData inputData, string ProductionOrderName)
        {
            //verifica se a ordem já está cadastrada no banco
            Order order = await _orderService.getProductionOrderId(inputData.productionOrderId);

            if (order == null)
            {
                Order orderNew = new Order();
                orderNew.productionOrderId = inputData.productionOrderId;
                orderNew.order             = ProductionOrderName;
                orderNew.productsInput     = new List <ProductTraceability>();
                orderNew.productsOutput    = new List <ProductTraceability>();

                order = await _orderService.addOrder(orderNew);
            }

            switch (inputData.type)
            {
            case typeEnum.Input:
                order.productsInput.Add(product);
                break;

            case typeEnum.Output:
                order.productsOutput.Add(product);
                break;
            }

            await _orderService.updateOrder(order.id, order);

            return(product);
        }
Exemplo n.º 2
0
        private ProductTraceability CreateProduct(InputData inputData, string ProductName)
        {
            ProductTraceability product = new ProductTraceability();

            product.productId   = inputData.productId;
            product.product     = ProductName;
            product.batch       = inputData.batch;
            product.quantity    = inputData.quantity.Value;
            product.date        = DateTime.Now.Ticks;
            product.username    = inputData.username;
            product.code        = inputData.code;
            product.productType = inputData.productType;
            return(product);
        }
Exemplo n.º 3
0
        public async Task <InputData> addProduct(InputData inputData)
        {
            ProductTraceability product = null;
            bool   checkRecipe          = false;
            string ProductName          = string.Empty;
            string ProductionOrderName  = string.Empty;
            // Faz get na receita
            string OrderRecipe = await GetProductionOrderApi(inputData.productionOrderId);

            if (OrderRecipe == null)
            {
                return(null);
            }

            // Verifica tipo de processo input ou output
            switch (inputData.type)
            {
            case typeEnum.Input:
                (checkRecipe, ProductName, ProductionOrderName) = CheckProductInRecipe(inputData.productId, OrderRecipe);
                break;

            case typeEnum.Output:
                (checkRecipe, ProductName, ProductionOrderName) = CheckProductOutRecipe(inputData.productId, OrderRecipe);
                break;
            }

            // Verifica se o produto está na receita
            if (!checkRecipe)
            {
                return(null);
            }

            product = CreateProduct(inputData, ProductName);

            product = await AddInDB(product, inputData, ProductionOrderName);

            return(inputData);
        }