Exemple #1
0
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]
                                              HttpRequest request,
                                              CancellationToken cancellationToken)
        {
            try
            {
                var sensorBoxId = request.GetQueryParameterDictionary()["sensorBoxId"];
                var sensorType  = Enum.Parse <SensorType>(request.GetQueryParameterDictionary()["sensorType"]);
                var sensor      = await _sensorService.GetByBoxIdAndTypeAsync(sensorBoxId, sensorType);

                return(sensor != null ? (IActionResult) new OkObjectResult(sensor) : new NotFoundResult());
            }
            catch (Exception e) when(e is KeyNotFoundException || e is ArgumentException)
            {
                return(new BadRequestResult());
            }
        }