public async Task <IActionResult> GetGroup(int id) { var(thingGroup, resultCode) = await _thingGroupService.getGroup(id); switch (resultCode) { case HttpStatusCode.OK: return(Ok(thingGroup)); case HttpStatusCode.NotFound: return(NotFound()); } return(StatusCode(StatusCodes.Status500InternalServerError)); }
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 <(Tool, string)> AssociateTool(int thingId, int toolId) { var tool = await _toolService.getTool(toolId); if (tool == null) { return(null, "Tool Not Found"); } var availableTools = await _toolService.getToolsAvailable(); if (availableTools.Where(x => x.toolId == toolId).Count() < 1) { return(null, "Tool Not Available"); } var toolType = await _toolTypeService.getToolType(tool.typeId.Value); if (toolType == null) { return(null, "Tool Type Not Found"); } var thingGroups = toolType.thingGroups; bool contains = false; foreach (var group in thingGroups) { var(completeGroup, status) = await _thingGroupService.getGroup(group.thingGroupId); if (status == HttpStatusCode.OK) { contains = completeGroup.things.Select(x => x.thingId).Contains(thingId); } } if (!contains) { return(null, "This Tool can't be associated with this thing."); } return(tool, "Tool Set to Use"); }