public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "appointment/{repo}/{id}")] HttpRequest req, string repo, string id, ILogger log) { log.LogInformation(string.Format("DeleteAppointment(): Received request to delete appointment with keys {0} {1}", repo, id)); try { var table = CosmosTableUtil.GetTableReference("schedule"); TableEntity appointment = await AppointmentData.GetAppointmentAsync(repo, id); if (appointment != null) { var result = await table.ExecuteAsync(TableOperation.Delete(appointment)); return(new OkObjectResult(result.Result as AppointmentEntity)); } else { return(new NotFoundResult()); } } catch (Exception ex) { log.LogError(string.Format("DeleteAppointment(): Exception occurred {0}:{1}", ex.Message, ex)); return(new InternalServerErrorResult()); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "appointment/{repo}/{id}")] HttpRequest req, string repo, string id, ILogger log) { log.LogInformation("Appointment(): Received request"); var result = await AppointmentData.GetAppointmentAsync(repo, id); return(new OkObjectResult(result)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "appointment/{repo}/{id}")] HttpRequest req, string repo, string id, ILogger log) { log.LogInformation("UpdateAppointment(): Received request"); using StreamReader reader = new StreamReader(req.Body); try { string requestBody = reader.ReadToEnd(); AppointmentEntity appointmentEntity = JsonConvert.DeserializeObject <AppointmentEntity>(requestBody); var table = CosmosTableUtil.GetTableReference("schedule"); var appointment = await AppointmentData.GetAppointmentAsync(repo, id); if (appointment != null) { appointment.Status = appointmentEntity.Status; var expert = await ExpertData.GetExpertAsync(appointment.Expert); // Update record var result = await table.ExecuteAsync(TableOperation.InsertOrReplace(appointment)); // Send email to expert await EmailUtil.SendEmailAsync(appointment, expert); return(new OkResult()); } else { return(new NotFoundResult()); } } catch (Exception ex) { log.LogError(string.Format("UpdateAppointment(): Exception occurred {0}:{1}", ex.Message, ex.InnerException)); return(new InternalServerErrorResult()); } }