Example #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "areaexit")] HttpRequest req,
            ILogger log, CancellationToken cancellationToken)
        {
            try
            {
                var data = await req.DeserializeJsonBody <NotifyAreaExitRequest>();

                var verificationQuery = new VerifyRequestQuery(data, req);
                var isVerified        = await mediator.Send(verificationQuery, cancellationToken);

                if (!isVerified)
                {
                    return(new UnauthorizedResult());
                }

                var command = new NotifyAreaExitCommand(data.ProfileId, data.DeviceId, data.Severity, data.RecordTimestamp);
                await mediator.Send(command, cancellationToken);

                return(new OkResult());
            }
            catch (DomainException ex)
            {
                var errors = validation.ProcessErrors(ex);
                return(new BadRequestObjectResult(errors));
            }
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log, CancellationToken cancellationToken)
        {
            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var    data        = JsonConvert.DeserializeObject <NotifyAreaExitRequest>(requestBody);
                var    command     = new NotifyAreaExitCommand(data.ProfileId, data.DeviceId, data.Latitude, data.Longitude, data.Accuracy, data.RecordTimestamp);
                await mediator.Send(command, cancellationToken);

                return(new OkResult());
            }
            catch (DomainException ex)
            {
                var errors = validation.ProcessErrors(ex);
                return(new BadRequestObjectResult(errors));
            }
        }