// Accepts a response from a participant public async Task SetResponseAsync(AppointmentResponse response) { // Just to make sure this response came from one of participants if (!this.Participants.Contains(response.NickName)) { return; } // If someone has rejected... if (!response.IsAccepted) { // ... then notifying everybody and killing ourselves await this.NotifyParticipants(this.Participants.ToArray(), AppointmentStatusEnum.Declined); Entity.Current.DeleteState(); return; } this.ParticipantsAccepted.Add(response.NickName); // If everybody have accepted if (this.Participants.SetEquals(this.ParticipantsAccepted)) { // ... then notifying everybody and killing ourselves await this.NotifyParticipants(this.Participants.ToArray(), AppointmentStatusEnum.Accepted); Entity.Current.DeleteState(); } }
public static async Task <IActionResult> RespondToAppointment( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "appointments/{appointmentId}")] HttpRequest request, string appointmentId, [DurableClient] IDurableClient durableClient, ILogger log) { var status = Enum.Parse <AppointmentStatusEnum>(await request.ReadAsStringAsync()); if (status == AppointmentStatusEnum.Pending) { return(new BadRequestResult()); } // Transforming client's response into a Signal var response = new AppointmentResponse { NickName = request.Headers[NickNameHeaderName], IsAccepted = (status == AppointmentStatusEnum.Accepted) }; await durableClient.SignalEntityAsync <IAppointmentEntity>(appointmentId, p => p.SetResponseAsync(response)); return(new OkResult()); }