Exemple #1
0
        public static async Task <HttpResponseMessage> PutAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "httpmonitors/{httpMonitorId}")] HttpRequestMessage req,
            string httpMonitorId,
            TraceWriter log,
            [Inject] IHttpMonitorService service,
            [Inject] JsonMediaTypeFormatter formatter)
        {
            if (!HttpMonitorId.TryParse(httpMonitorId, out var id))
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                var cmd = await req.Content.ReadAsAsync <UpdateHttpMonitor>(new[] { formatter });

                cmd.HttpMonitorId = id;

                var httpMonitor = await service.UpdateHttpMonitorAsync(cmd);

                return(req.CreateResponse(HttpStatusCode.OK, httpMonitor, formatter));
            }
            catch (EntityNotFoundException)
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }
        }
        public async Task <IActionResult> Put(HttpMonitorId httpMonitorId, [FromBody] UpdateHttpMonitor command)
        {
            command.HttpMonitorId = httpMonitorId;

            try
            {
                var httpMonitor = await _service.UpdateHttpMonitorAsync(command);

                return(Ok(httpMonitor));
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
        }