public async Task <(ProductionOrder, string)> AssociateProductionOrder(int thingId, int productioOrderId)
        {
            var PO = await _productionOrderService.getProductionOrder(productioOrderId);

            if (PO == null)
            {
                return(null, "Production Order Not Found");
            }
            if (PO.currentStatus != stateEnum.active.ToString())
            {
                return(null, "Production Order must be Active to Be set in Production");
            }
            var POType = await _productionOrderTypeService.getProductionOrderType(PO.productionOrderTypeId.Value);

            if (POType == null)
            {
                return(null, "Production Order Type Not Found");
            }
            var POOnThing = await _productionOrderService.getProductionOrderOnThing(thingId);

            var  thingGroups = POType.thingGroups;
            bool contains    = false;

            foreach (var group in thingGroups)
            {
                var(completeGroup, status) = await _thingGroupService.getGroup(group.thingGroupId);

                if (status == HttpStatusCode.OK)
                {
                    if (completeGroup.things.Select(x => x.thingId).Contains(thingId) == true)
                    {
                        contains = true;
                    }
                }
            }
            if (!contains)
            {
                return(null, "This Production Order can't  be associated with this thing.");
            }
            await _productionOrderService.setProductionOrderToThing(PO, thingId);

            UpdateStatusAPI(POType.typeScope, POType.typeDescription, "productionOrderNumber", PO.productionOrderNumber, thingId);
            Trigger(PO);
            PO = await _productionOrderService.getProductionOrder(productioOrderId);

            return(PO, "Production Order Set to Thing");
        }
        public async Task <IActionResult> Get(int id)
        {
            var productionOrder = await _productionOrderService.getProductionOrder(id);

            if (productionOrder == null)
            {
                return(NotFound());
            }
            return(Ok(productionOrder));
        }
示例#3
0
        public async Task <Genealogy> instanciaG(InputData inputData)
        {
            Genealogy g = new Genealogy();
            var       productionOrder = await _productionOrderService.getProductionOrder(inputData.productionOrderId);

            builder = new UriBuilder(_configuration["productionOrdersServiceEndpoint"] + "/api/productionorders/" + inputData.productionOrderId);
            Recipe r = JsonConvert.DeserializeObject <Recipe>(JObject.Parse((await client.GetStringAsync(builder.ToString())))["recipe"].ToString());

            Console.WriteLine(r.recipeId);
            g = new Genealogy(inputData.productionOrderId, productionOrder.productionOrderNumber, (await getStartDateRoll(productionOrder.productionOrderId)), DateTime.Now.Ticks, new List <EndRoll>(), r.recipeCode, r.recipeId.ToString()); g.endDate = DateTime.Now.Ticks;
            return(g);
        }
示例#4
0
        public async Task <IActionResult> GetProductionOrder([FromQuery] int?startat, [FromQuery] int?quantity, [FromQuery] string fieldFilter = null, [FromQuery] string fieldValue = null, [FromQuery] string orderField = null, [FromQuery] string order = null)
        {
            var(productionOrder, resultCode) = await _productionOrderService.getProductionOrder(startat, quantity, fieldFilter, fieldValue, orderField, order);

            switch (resultCode)
            {
            case HttpStatusCode.OK:
                return(Ok(productionOrder));

            case HttpStatusCode.NotFound:
                return(NotFound());
            }
            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
        public async Task <IActionResult> GetRecipe(int id)
        {
            var productionOrder = await _productionOrderService.getProductionOrder(id);

            return(Ok(productionOrder));
        }