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); }
public async Task <List <AlarmCurrent> > GetAlarmPerThingId(int thingId) { var alarmDb = await _context.AlarmCurrents .Where(x => x.thingId == thingId) .ToListAsync(); var alarmCurrent = ConvertAlarmInAlarmCurrent(alarmDb); foreach (var alarmCur in alarmCurrent) { var(thing, status) = await _thingservice.getThing(alarmCur.thingId); if (status == HttpStatusCode.OK) { alarmCur.thing = thing; foreach (var alarm in alarmCur.alarms) { if (alarm.thing != null) { var(innerThing, innerStatus) = await _thingservice.getThing(alarm.thingId.Value); if (innerStatus == HttpStatusCode.OK) { alarm.thing = innerThing; } } } } } return(alarmCurrent); }
public async Task <ThingStatus> getCurrentStatus(int thingId) { var status = await _context.ActiveThingStatus .Where(x => x.thingId == thingId) .Include(x => x.statusContexts) .FirstOrDefaultAsync(); var(thing, code) = await _thingService.getThing(thingId); if (code != HttpStatusCode.OK) { return(null); } status.thing = thing; return(status); }
public async Task <ProductionOrder> getProductionOrder(int productionOrderId) { var productionOrder = await _context.ProductionOrders .Include(x => x.recipe) .Include(x => x.recipe.phases) .Include(x => x.recipe.recipeProduct) .Include(x => x.recipe.recipeProduct.product) .Include("recipe.phases.phaseProducts") .Include("recipe.phases.phaseParameters") .Include("recipe.phases.phaseParameters.tag") .Include("recipe.phases.phaseParameters.tag.thingGroup") .Include("recipe.phases.phaseParameters.tag.thingGroup.things") .Include("recipe.phases.phaseProducts.product") .Where(x => x.productionOrderId == productionOrderId) .AsNoTracking() .FirstOrDefaultAsync(); if (productionOrder == null) { return(null); } var productionOrderType = await _productionOrderTypeService.getProductionOrderType(productionOrder.productionOrderTypeId.Value); if (productionOrderType != null) { productionOrder.typeDescription = productionOrderType.typeDescription; } if (productionOrder.currentThingId != null) { var(thing, status) = await _thingService.getThing(productionOrder.currentThingId.Value); if (status == HttpStatusCode.OK) { productionOrder.currentThing = thing; } } return(productionOrder); }
public async Task <IActionResult> GetThing(int id) { var(thing, resultCode) = await _thingService.getThing(id); switch (resultCode) { case HttpStatusCode.OK: return(Ok(thing)); case HttpStatusCode.NotFound: return(NotFound()); } return(StatusCode(StatusCodes.Status500InternalServerError)); }