public static async Task <IActionResult> UpdateSeminar( [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "seminars/{id}")] HttpRequest req, [Table("Seminars")] CloudTable table, ILogger log, string id) { log.LogInformation($"Updating seminar with ID {id}"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var input = JsonConvert.DeserializeObject <SeminarUpdateModel>(requestBody); var filter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, id); var result = await table.ExecuteQueryAsync(new TableQuery <SeminarTableEntity>().Where(filter)); if (!result.Any()) { return(new NotFoundResult()); } var original = result.First().ToModel(); var entity = new Seminar() { Id = original.Id, Name = input.Name ?? original.Name, Information = input.Information ?? original.Information, Duration = input.Duration ?? original.Duration, StartDate = input.StartDate ?? original.StartDate }; await table.ExecuteAsync(TableOperation.Replace(entity.ToTableEntity())); return(new OkObjectResult(entity)); }
public static async Task <IActionResult> CreateSeminar( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "seminars")] HttpRequest req, [Table("Seminars")] CloudTable table, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation($"Creating a seminar: {requestBody}"); var input = JsonConvert.DeserializeObject <SeminarCreateModel>(requestBody); var entity = new Seminar() { Id = Guid.NewGuid().ToString(), Name = input.Name, Information = input.Information, Duration = input.Duration, StartDate = input.StartDate }; await table.ExecuteAsync(TableOperation.Insert(entity.ToTableEntity())); return(new OkObjectResult(entity)); }