From 7d82832e42d0e0df6a22f1925d850d8dd48834f6 Mon Sep 17 00:00:00 2001 From: jojo aquino Date: Mon, 24 Mar 2025 09:11:24 +0000 Subject: [PATCH] sort waiting participants by SortOrder --- .../Participant/VideoCall/Waiting.cshtml.cs | 48 +++++++++++-------- .../WaitingForParticipantViewModel.cs | 1 + 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/Waiting.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/Waiting.cshtml.cs index dca1a41..cc8699b 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/Waiting.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/Waiting.cshtml.cs @@ -9,57 +9,65 @@ namespace EnotaryoPH.Web.Pages.Participant.VideoCall { private readonly NotaryoDBContext _dbContext; private readonly ICurrentUserService _currentUserService; + private readonly IConferenceSheduleService _conferenceSheduleService; private Transaction _transactionEntity; - public WaitingModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService) + public WaitingModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService, IConferenceSheduleService conferenceSheduleService) { _dbContext = notaryoDBContext; _currentUserService = currentUserService; + _conferenceSheduleService = conferenceSheduleService; } - public IActionResult OnGet() + public async Task OnGetAsync() { _transactionEntity = _dbContext.Transactions .Include(t => t.TransactionSignatories) .ThenInclude(ts => ts.User) .Include(t => t.Lawyer) + .ThenInclude(l => l.User) .Include(t => t.Principal) .FirstOrDefault(t => t.Transaction_UID == Transaction_UID); - if (_transactionEntity == null) + if (_transactionEntity == null || _transactionEntity.Status.IsInList(TransactionState.Completed)) { return NotFound(); } + var schedule_UID = await _conferenceSheduleService.GetOrCreateScheduleIDAsync(Transaction_UID); + if (schedule_UID != Guid.Empty) + { + return Redirect($"/Participant/VideoCall/Room/{Transaction_UID}"); + } + var participants = _transactionEntity.TransactionSignatories - .Select(t => new WaitingForParticipantViewModel + .ConvertAll(t => new WaitingForParticipantViewModel { Email = t.Email, Status = ConvertToWaitingStatus(t.Status), - Type = t.Email == _currentUserService.GetEmail() ? "(You)" : t.Type, - UID = t.TransactionSignatory_UID.GetValueOrDefault() - }) - .ToList(); - - if (_transactionEntity.LawyerID > 0) - { - participants.Add(new WaitingForParticipantViewModel - { - Email = _transactionEntity.Lawyer.User.Email, - Status = "Waiting", - Type = nameof(UserType.Notary), - UID = Guid.Empty + Type = string.Equals(t.Email, _currentUserService.GetEmail(), StringComparison.OrdinalIgnoreCase) ? "(You)" : t.Type, + UID = t.TransactionSignatory_UID.GetValueOrDefault(), + SortOrder = 3 }); - } + + participants.Add(new WaitingForParticipantViewModel + { + Email = _transactionEntity.Lawyer?.User?.Email ?? "notarypublic@enotaryo.ph", + Status = "Waiting", + Type = nameof(UserType.Notary), + UID = _transactionEntity.Lawyer?.User?.User_UID ?? Guid.Empty, + SortOrder = 1 + }); participants.Add(new WaitingForParticipantViewModel { Email = _transactionEntity.Principal.Email, Status = "Ready", Type = nameof(UserType.Principal), - UID = Guid.Empty + UID = _transactionEntity.Principal?.User_UID ?? Guid.Empty, + SortOrder = 2 }); - Participants = participants.OrderBy(p => p.Type).ToList(); + Participants = participants.OrderBy(p => p.SortOrder).ThenBy(p => p.Email).ToList(); return Page(); } diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/WaitingForParticipantViewModel.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/WaitingForParticipantViewModel.cs index df19422..a61d9f7 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/WaitingForParticipantViewModel.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/VideoCall/WaitingForParticipantViewModel.cs @@ -6,5 +6,6 @@ public string Status { get; set; } public string Type { get; set; } public Guid UID { get; set; } + public int SortOrder { get; set; } } } \ No newline at end of file