Exemplo n.º 1
0
        public async Task <List <Tool> > getToolsAvailable()
        {
            var tools = await _context.Tools
                        .Where(x => x.currentThingId == null && x.status == stateEnum.available.ToString()).Include(x => x.toolType)
                        .ToListAsync();

            foreach (var tool in tools)
            {
                var toolType = await _toolTypeService.getToolType(tool.typeId.Value);

                tool.typeName          = toolType.name;
                tool.lifeCycle         = toolType.lifeCycle;
                tool.unitOfMeasurement = toolType.unitOfMeasurement;

                if (tool.currentThingId != null)
                {
                    var(thing, status) = await _thingService.getThing(tool.currentThingId.Value);

                    if (status == HttpStatusCode.OK)
                    {
                        tool.currentThing = thing;
                    }
                }
            }
            return(tools);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetId(int id)
        {
            try {
                var toolType = await _toolTypeService.getToolType(id);

                return(Ok(toolType));
            } catch (Exception ex) {
                return(StatusCode(500, ex.Message));
            }
        }
        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");
        }