Пример #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Start finding scooters");
            try
            {
                var          requestBody   = await new StreamReader(req.Body).ReadToEndAsync();
                TripLocation riderLocation = JsonConvert.DeserializeObject <TripLocation>(requestBody);

                // find all scooters around the rider location. Get data from cosmos db scooter collection
                var scooters = await _scooterService.FindScootersInRange(riderLocation.Longitude, riderLocation.Latitude, riderLocation.Distance);

                if (scooters.Any())
                {
                    return((ActionResult) new OkObjectResult(scooters));
                }

                return(new NoContentResult());
            }
            catch (Exception e)
            {
                log.LogError(e.Message);
                return(new BadRequestObjectResult("An error occured!"));
            }
        }