From 33c07d58c9801699ab75c32021b4760e5f4a0f4a Mon Sep 17 00:00:00 2001 From: Robert Brands Date: Sat, 16 Sep 2023 20:13:37 +0300 Subject: [PATCH] Fix waiting list for Co-Guides (#131) * Presentation * Waiting list for co-guides --------- Co-authored-by: Robert Brands (RiwaAdmin) --- MeetUpFunctions/AddCoGuide.cs | 32 +++++++++---------- .../RemoveParticipantFromCalendarItem.cs | 18 +++++++++-- MeetUpPlanner/Client/Pages/Calendar.razor | 2 +- MeetUpPlanner/Client/Shared/MeetUp.razor | 2 +- MeetUpPlanner/Shared/ExtendedCalendarItem.cs | 6 +++- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/MeetUpFunctions/AddCoGuide.cs b/MeetUpFunctions/AddCoGuide.cs index a4ae718..6a2606a 100644 --- a/MeetUpFunctions/AddCoGuide.cs +++ b/MeetUpFunctions/AddCoGuide.cs @@ -73,6 +73,7 @@ public async Task Run( // already registered alreadyRegistered = true; participant.Id = p.Id; + participant.IsWaiting = p.IsWaiting; } if (!p.IsWaiting) { @@ -93,27 +94,24 @@ public async Task Run( // Admin can "overbook" a meetup to be able to add some extra guests maxRegistrationCount *= Constants.ADMINOVERBOOKFACTOR; } - // Add extra slots for guides + // Add extra slots for co-guides if (coGuideCounter < calendarItem.MaxCoGuidesCount) { - maxRegistrationCount += (calendarItem.MaxCoGuidesCount - coGuideCounter); + maxRegistrationCount += calendarItem.MaxCoGuidesCount; } - if (!alreadyRegistered) + if (counter < maxRegistrationCount) { - if (counter < maxRegistrationCount) - { - ++counter; - participant.IsWaiting = false; - } - else if (waitingCounter < calendarItem.MaxWaitingList) - { - ++waitingCounter; - participant.IsWaiting = true; - } - else - { - return new OkObjectResult(new BackendResult(false, "Maximale Anzahl Registrierungen bereits erreicht.")); - } + ++counter; + participant.IsWaiting = false; + } + else if (waitingCounter < calendarItem.MaxWaitingList) + { + ++waitingCounter; + participant.IsWaiting = true; + } + else + { + return new OkObjectResult(new BackendResult(false, "Maximale Anzahl Registrierungen bereits erreicht.")); } // Set TTL for participant the same as for CalendarItem System.TimeSpan diffTime = calendarItem.StartDate.Subtract(DateTime.Now); diff --git a/MeetUpFunctions/RemoveParticipantFromCalendarItem.cs b/MeetUpFunctions/RemoveParticipantFromCalendarItem.cs index 5b39f6c..5cb6aa7 100644 --- a/MeetUpFunctions/RemoveParticipantFromCalendarItem.cs +++ b/MeetUpFunctions/RemoveParticipantFromCalendarItem.cs @@ -74,16 +74,28 @@ public async Task Run( if (!participant.IsWaiting) { IEnumerable participants = await _cosmosRepository.GetItems(p => p.CalendarItemId.Equals(participant.CalendarItemId)); + int counter = 0; + int coGuideCounter = 0; foreach (Participant p in participants) { + if (!p.IsWaiting) counter++; if (!p.Id.Equals(participant.Id) && p.IsWaiting) { - p.IsWaiting = false; - await _cosmosRepository.UpsertItem(p); CalendarItem calendarItem = await _calendarRepository.GetItem(p.CalendarItemId); - await _subscriptionRepository.NotifyParticipant(calendarItem, p, "Das Warten hat sich gelohnt - Du bist jetzt angemeldet."); + int maxRegistrationCount = calendarItem.MaxRegistrationsCount; + if (p.IsCoGuide) + { + maxRegistrationCount += (calendarItem.MaxCoGuidesCount - coGuideCounter); + } + if (counter < maxRegistrationCount) + { + p.IsWaiting = false; + await _cosmosRepository.UpsertItem(p); + await _subscriptionRepository.NotifyParticipant(calendarItem, p, "Das Warten hat sich gelohnt - Du bist jetzt angemeldet."); + } break; // only the first one from waiting list can be promoted } + if (p.IsCoGuide) coGuideCounter++; } } await _cosmosRepository.DeleteItemAsync(participant.Id); diff --git a/MeetUpPlanner/Client/Pages/Calendar.razor b/MeetUpPlanner/Client/Pages/Calendar.razor index 2f9ef5e..33b7f35 100644 --- a/MeetUpPlanner/Client/Pages/Calendar.razor +++ b/MeetUpPlanner/Client/Pages/Calendar.razor @@ -128,7 +128,7 @@ { Min @item.MinRegistrationsCount } - : @item.HostDisplayName(AppStateStore.ClientSettings.NameDisplayLength)@item.ParticipantsDisplay(AppStateStore.ClientSettings.NameDisplayLength) + : @item.HostDisplayName(AppStateStore.ClientSettings.NameDisplayLength)@((MarkupString)item.ParticipantsDisplay(AppStateStore.ClientSettings.NameDisplayLength)) @if (0 < item.WaitingListCounter) {
diff --git a/MeetUpPlanner/Client/Shared/MeetUp.razor b/MeetUpPlanner/Client/Shared/MeetUp.razor index 2461522..7156602 100644 --- a/MeetUpPlanner/Client/Shared/MeetUp.razor +++ b/MeetUpPlanner/Client/Shared/MeetUp.razor @@ -30,7 +30,7 @@ { Min @CalendarItem.MinRegistrationsCount } - : @CalendarItem.HostDisplayName(NameDisplayLength)@CalendarItem.ParticipantsDisplay(NameDisplayLength) + : @CalendarItem.HostDisplayName(NameDisplayLength)@((MarkupString)CalendarItem.ParticipantsDisplay(NameDisplayLength)) } else { diff --git a/MeetUpPlanner/Shared/ExtendedCalendarItem.cs b/MeetUpPlanner/Shared/ExtendedCalendarItem.cs index 175d187..f66d1ed 100644 --- a/MeetUpPlanner/Shared/ExtendedCalendarItem.cs +++ b/MeetUpPlanner/Shared/ExtendedCalendarItem.cs @@ -80,10 +80,14 @@ public string ParticipantsDisplay(int nameDisplayLength) { sb.Append(", "); } + if (participant.IsCoGuide && coGuideCounter <= this.MaxCoGuidesCount) + { + sb.Append(""); + } sb.Append(participant.ParticipantDisplayName(nameDisplayLength)); if (participant.IsCoGuide && coGuideCounter <= this.MaxCoGuidesCount) { - sb.Append("(Co-Guide)"); + sb.Append("(Co-Guide)"); } ++counter; }