public static async Task <HttpResponseMessage> CreateObject( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req, ILogger log, ClaimsPrincipal claimsPrinciple) { try { log.LogInformation("User:" + claimsPrinciple.Identity.Name); var json = await req.Content.ReadAsStringAsync(); var objectInfo = JsonConvert.DeserializeObject <ObjectInfo>(json); objectInfo.createdBy = claimsPrinciple.Identity.Name; await CloudTableExtensions.AddOrUpdateToTable(objectInfo); return(req.CreateResponse(HttpStatusCode.Created, objectInfo)); } catch (Exception e) { log.LogError(e.Message); log.LogError(e.StackTrace); return(req.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); throw e; } }
public static async Task <HttpResponseMessage> UpdateObject([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "objects/{id}")] HttpRequestMessage req, string id, ILogger log, ExecutionContext context, ClaimsPrincipal claimsPrincipal) { Stopwatch stopWatch = new Stopwatch(); var json = await req.Content.ReadAsStringAsync(); var item = JsonConvert.DeserializeObject <ObjectInfo>(json); var oldItem = await CloudTableExtensions.GetObjFromTable(id, claimsPrincipal.Identity.Name); item.id = id; // ensure item id matches id passed in item.isComplete = oldItem.isComplete; // ensure we don't change isComplete item.createdBy = claimsPrincipal.Identity.Name; await CloudTableExtensions.AddOrUpdateToTable(item); stopWatch.Stop(); var metrics = new Dictionary <string, double> { { "processingTime", stopWatch.Elapsed.TotalMilliseconds } }; var props = new Dictionary <string, string> { { "object-id", id } }; TelemetryClient telemetryClient = telemetryFactory.GetClient(context); telemetryClient.TrackEvent("update-object", properties: props, metrics: metrics); return(req.CreateResponse(HttpStatusCode.OK, item)); }