public async Task ExecuteAsync(CreateStudyRoomSessionCommand message, CancellationToken token) { var room = await _studyRoomRepository.LoadAsync(message.StudyRoomId, token); if (room.Tutor.Id != message.UserId) //only tutor can open a session { throw new ArgumentException(); } var lastSession = room.GetCurrentSession(); if (lastSession != null) { var roomAvailable = await _videoProvider.GetRoomAvailableAsync(lastSession.SessionId); if (roomAvailable) { lastSession.ReJoinStudyRoom(); return; } } var sessionName = $"{message.StudyRoomId}_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}"; await _videoProvider.CreateRoomAsync(sessionName, room.Tutor.User.Country, message.RecordVideo, message.CallbackUrl, room.Type.GetValueOrDefault(StudyRoomType.PeerToPeer) ); var session = new StudyRoomSession(room, sessionName); room.AddSession(session); }
public async Task <IEnumerable <PaymentDto> > GetAsync(PaymentsQuery query, CancellationToken token) { StudyRoomSession studyRoomSessionAlias = null; StudyRoom studyRoomAlias = null; Core.Entities.Tutor tutorAlias = null; StudyRoomUser studyRoomUserAlias = null; User studentAlias = null; User tutorUserAlias = null; PaymentDto resultDto = null; var res = _session.QueryOver(() => studyRoomSessionAlias) .JoinAlias(x => x.StudyRoom, () => studyRoomAlias) .JoinEntityAlias(() => tutorAlias, () => studyRoomAlias.Tutor.Id == tutorAlias.Id) .JoinEntityAlias(() => studyRoomUserAlias, () => studyRoomAlias.Id == studyRoomUserAlias.Room.Id && tutorAlias.Id != studyRoomUserAlias.User.Id) .JoinEntityAlias(() => studentAlias, () => studyRoomUserAlias.User.Id == studentAlias.Id) .JoinEntityAlias(() => tutorUserAlias, () => tutorUserAlias.Id == tutorAlias.User.Id) .Where(w => w.Receipt == null) .Where(w => w.Duration.Value > TimeSpan.FromMinutes(10)); if (!string.IsNullOrEmpty(query.Country)) { res = res.Where(w => studentAlias.Country == query.Country || tutorUserAlias.Country == query.Country); } return(await res.SelectList(sl => sl.Select(s => s.Id).WithAlias(() => resultDto.StudyRoomSessionId) .Select(s => s.Price).WithAlias(() => resultDto.Price) .Select(Projections.Conditional( Restrictions.IsNull(Projections.Property(() => tutorAlias.SellerKey)), Projections.Constant(false), Projections.Constant(true) )).WithAlias(() => resultDto.IsSellerKeyExists) .Select(Projections.Conditional( Restrictions.Eq(Projections.Property(() => studentAlias.PaymentExists), PaymentStatus.None), Projections.Constant(false), Projections.Constant(true) )).WithAlias(() => resultDto.IsPaymentKeyExists) .Select(s => tutorAlias.Id).WithAlias(() => resultDto.TutorId) .Select(s => tutorUserAlias.Name).WithAlias(() => resultDto.TutorName) .Select(s => studentAlias.Id).WithAlias(() => resultDto.UserId) .Select(s => studentAlias.Name).WithAlias(() => resultDto.UserName) .Select(s => s.Created).WithAlias(() => resultDto.Created) .Select(s => s.Duration.Value).WithAlias(() => resultDto.Duration).WithAlias(() => resultDto.Duration) .Select(s => s.RealDuration.Value).WithAlias(() => resultDto.RealDuration).WithAlias(() => resultDto.RealDuration) //.Select(Projections.SqlFunction("COALESCE", NHibernateUtil.TimeSpan // , Projections.Property<StudyRoomSession>(s => s.RealDuration.Value) // , Projections.Property<StudyRoomSession>(s => s.Duration.Value)) //).WithAlias(() => resultDto.Duration) .Select(Projections.Conditional( Restrictions.IsNull(Projections.Property <StudyRoomSession>(s => s.RealDuration)), Projections.Constant(false), Projections.Constant(true) )).WithAlias(() => resultDto.IsRealDurationExitsts) ).TransformUsing(Transformers.AliasToBean <PaymentDto>()) .ListAsync <PaymentDto>()); }
public void EndSession_WithoutSubsidizedPrice_Ok() { _tutorMoq.Setup(s => s.Price).Returns(new TutorPrice(10, 5)); var studyRoomSession = new StudyRoomSession(_studyRoom.Object, "testId"); var prop = studyRoomSession.GetType().GetProperty("Created"); prop.SetValue(studyRoomSession, DateTime.UtcNow.AddHours(-1)); studyRoomSession.EndSession(); studyRoomSession.Price.Should().NotBeNull(); studyRoomSession.Price.Should().Be(5M); }
private async Task DoProcessAsync(StudyRoomSession studyRoomSession, CancellationToken token) { var users = studyRoomSession.StudyRoom.Users; var session = studyRoomSession.SessionId; var tasks = new List <Task>(); foreach (var user in users) { var jwtToken = await _videoProvider.ConnectToRoomAsync(session, user.User.Id.ToString()); var message = new SignalRTransportType(SignalRType.StudyRoom, SignalREventAction.StartSession, new { jwtToken }); var t = _hubContext.Clients.User(user.User.Id.ToString()).SendAsync(SbHub.MethodName, message, token); tasks.Add(t); } await Task.WhenAll(tasks); }
public EndStudyRoomSessionEvent(StudyRoomSession session) { Session = session; }
public StudyRoomSessionRejoinEvent(StudyRoomSession studyRoomSession) { StudyRoomSession = studyRoomSession; }
public StudyRoomSessionCreatedEvent(StudyRoomSession studyRoomSession) { StudyRoomSession = studyRoomSession; }