109 lines
4.8 KiB
C#
109 lines
4.8 KiB
C#
using EnotaryoPH.Data;
|
|
using EnotaryoPH.Data.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace EnotaryoPH.Web.Pages.Participant.VideoCall
|
|
{
|
|
public class RoomModel : PageModel
|
|
{
|
|
private readonly IConferenceSheduleService _conferenceSheduleService;
|
|
private readonly ICurrentUserService _currentUserService;
|
|
private readonly NotaryoDBContext _dbContext;
|
|
private LawyerVideoConferenceSchedule _LawyerVideoConferenceSchedule;
|
|
private Transaction _Transaction;
|
|
|
|
public RoomModel(ICurrentUserService currentUserService, NotaryoDBContext dbContext, IConferenceSheduleService conferenceSheduleService)
|
|
{
|
|
_currentUserService = currentUserService;
|
|
_dbContext = dbContext;
|
|
_conferenceSheduleService = conferenceSheduleService;
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
_Transaction = _dbContext.Transactions
|
|
.Include(t => t.TransactionSignatories)
|
|
.Include(t => t.Principal)
|
|
.FirstOrDefault(t => t.Transaction_UID == Transaction_UID);
|
|
if (_Transaction == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var currentUser = _dbContext.Users.Single(u => u.User_UID == _currentUserService.GetUser_UID());
|
|
var schedule_UID = await _conferenceSheduleService.GetOrCreateScheduleIDAsync(Transaction_UID);
|
|
if (schedule_UID == Guid.Empty)
|
|
{
|
|
if (_Transaction.PrincipalID == currentUser.UserID)
|
|
{
|
|
return Redirect($"/Principal/TransactionStatus/{Transaction_UID}");
|
|
}
|
|
|
|
if (currentUser.Role.IsInList(UserType.Principal, UserType.Witness))
|
|
{
|
|
return Redirect($"/Participant/VideoCall/Waiting/{Transaction_UID}");
|
|
}
|
|
|
|
return Redirect("/");
|
|
}
|
|
|
|
_LawyerVideoConferenceSchedule = _dbContext.LawyerVideoConferenceSchedules
|
|
.Include(sched => sched.LawyerVideoConferenceParticipants)
|
|
.ThenInclude(p => p.Participant)
|
|
.Include(sched => sched.Lawyer)
|
|
.ThenInclude(l => l.User)
|
|
.FirstOrDefault(sched => sched.LawyerVideoConferenceSchedule_UID == schedule_UID);
|
|
|
|
CommunicationUserToken = currentUser.Role == nameof(UserType.Notary)
|
|
? _LawyerVideoConferenceSchedule.MeetingRoomTokenID
|
|
: _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.First(u => u.ParticipantID == currentUser.UserID).MeetingRoomTokenID;
|
|
CommunicationRoomId = _LawyerVideoConferenceSchedule.MeetingRoomID;
|
|
CommunicationUserId = currentUser.Role == nameof(UserType.Notary)
|
|
? _LawyerVideoConferenceSchedule.MeetingRoomUserID
|
|
: _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.First(u => u.ParticipantID == currentUser.UserID).MeetingRoomUserID;
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task OnPostStartRecordingAsync() => await _conferenceSheduleService.StartRecordingAsync(Transaction_UID);
|
|
|
|
public string CommunicationRoomId { get; private set; }
|
|
|
|
public string CommunicationUserId { get; set; }
|
|
|
|
public string CommunicationUserToken { get; private set; }
|
|
|
|
public List<RoomParticipantViewModel> Participants
|
|
{
|
|
get
|
|
{
|
|
var signatoryTypes = _Transaction.TransactionSignatories.Where(t => t.UserID > 0).ToDictionary(k => k.UserID, v => v.Type);
|
|
var participants = _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.ConvertAll(p => new RoomParticipantViewModel
|
|
{
|
|
Id = p.LawyerVideoConferenceParticipant_UID.ToString(),
|
|
DisplayName = $"{p.Participant.Firstname} {p.Participant.Lastname}".Trim().DefaultIfEmpty(p.Participant.Email),
|
|
RoomUserID = p.MeetingRoomUserID,
|
|
Type = signatoryTypes.GetValueOrDefault(p.ParticipantID, nameof(UserType.Principal))
|
|
});
|
|
|
|
var host = _LawyerVideoConferenceSchedule.Lawyer.User;
|
|
participants.Add(new RoomParticipantViewModel
|
|
{
|
|
DisplayName = $"{host.Firstname} {host.Lastname}".Trim().DefaultIfEmpty(host.Email),
|
|
Id = Guid.Empty.ToString(),
|
|
RoomUserID = _LawyerVideoConferenceSchedule.MeetingRoomUserID,
|
|
Type = nameof(UserType.Notary)
|
|
});
|
|
|
|
return participants;
|
|
}
|
|
}
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string ServerCallingID { get; set; }
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public Guid Transaction_UID { get; set; }
|
|
}
|
|
} |