public async Task RemoveStudentTutor(string tutorId, int moduleId)
        {
            var currentUserId     = _currentUserService.GetUserId();
            var studentTutorQuery = await _studentTutorsRepository.GetFiltered(st =>
                                                                               st.StudentId == currentUserId &&
                                                                               st.TutorId == tutorId &&
                                                                               st.ModuleId == moduleId);

            var studentTutor = studentTutorQuery.FirstOrDefault();

            if (studentTutor != null)
            {
                await _studentTutorsRepository.Delete(studentTutor);

                await RemoveUpcomingTutoringSessions(currentUserId, tutorId, moduleId);

                var studentNotification = new TutoringSessionFinishedNotificationDto {
                    ParticipantId = tutorId
                };
                await _hubsService.SendSessionFinishedNotificationToUser(currentUserId, studentNotification);

                var tutorNotification = new TutoringSessionFinishedNotificationDto {
                    ParticipantId = currentUserId
                };
                await _hubsService.SendSessionFinishedNotificationToUser(tutorId, tutorNotification);
            }
        }
        public async Task IgnoreTutorStudent(string studentId)
        {
            var currentUserId = _currentUserService.GetUserId();
            var ignore        = new StudentTutorIgnore
            {
                StudentId = studentId,
                TutorId   = currentUserId
            };

            await _studentTutorIgnoresRepository.Create(ignore);

            await RemoveUpcomingTutoringSessions(studentId, currentUserId);

            var studentTutorEntities = await _studentTutorsRepository.GetFiltered(st => st.TutorId == currentUserId && st.StudentId == studentId);

            await _studentTutorsRepository.DeleteMany(studentTutorEntities);

            var tutorNotification = new TutoringSessionFinishedNotificationDto {
                ParticipantId = studentId
            };
            await _hubsService.SendSessionFinishedNotificationToUser(currentUserId, tutorNotification);

            var studentNotification = new TutoringSessionFinishedNotificationDto {
                ParticipantId = currentUserId
            };
            await _hubsService.SendSessionFinishedNotificationToUser(studentId, studentNotification);
        }
示例#3
0
 public async Task SendSessionFinishedNotificationToUser(string userId, TutoringSessionFinishedNotificationDto sessionNotification)
 {
     await _hubContext.Clients
     .User(userId)
     .SendAsync("tutoring-session-finished", sessionNotification);
 }
        public async Task RecheckUpcomingTutoringSessions()
        {
            var currentTime = _timeService.GetCurrentTime();
            var sessions    = await _tutoringSessionsRepository.GetFiltered(ts => ts.Status == TutoringSessionStatusEnum.Upcoming);

            foreach (var session in sessions)
            {
                var timeDifference = session.SessionDate - currentTime;

                if (timeDifference.TotalMinutes < -30)
                {
                    session.Status           = TutoringSessionStatusEnum.Finished;
                    session.StatusChangeDate = currentTime;
                    await _tutoringSessionsRepository.Update(session);

                    var studentNotification = new TutoringSessionFinishedNotificationDto {
                        SessionId = session.Id, ParticipantId = session.TutorId, TutorName = session.Tutor.FirstName + " " + session.Tutor.LastName, OpenNotificationDialog = true
                    };
                    var tutorNotification = new TutoringSessionFinishedNotificationDto {
                        ParticipantId = session.StudentId
                    };
                    await _hubsService.SendSessionFinishedNotificationToUser(session.StudentId, studentNotification);

                    await _hubsService.SendSessionFinishedNotificationToUser(session.TutorId, tutorNotification);

                    if (session.IsSubscribed)
                    {
                        var newSession = new TutoringSession
                        {
                            CreationDate = currentTime,
                            IsSubscribed = true,
                            ModuleId     = session.ModuleId,
                            SessionDate  = session.SessionDate.AddDays(7),
                            Status       = TutoringSessionStatusEnum.Upcoming,
                            StudentId    = session.StudentId,
                            TutorId      = session.TutorId
                        };

                        await _tutoringSessionsRepository.Create(newSession);
                    }
                }
                else if (timeDifference.TotalMinutes < 15 && !session.IsReminderSent)
                {
                    await _emailService.SendTutoringSessionReminder(session.Tutor.Email);

                    await _emailService.SendTutoringSessionReminder(session.Student.Email);

                    session.IsReminderSent = true;
                    await _tutoringSessionsRepository.Update(session);
                }
                else if (timeDifference.TotalMinutes < 0)
                {
                    var studentNotification = new TutoringSessionOnGoingDto
                    {
                        ModuleId      = session.ModuleId,
                        ParticipantId = session.TutorId,
                        IsStudent     = true
                    };
                    await _hubsService.SendSessionOnGoingNotificationToUser(session.StudentId, studentNotification);

                    var tutorNotification = new TutoringSessionOnGoingDto
                    {
                        ModuleId      = session.ModuleId,
                        ParticipantId = session.StudentId
                    };
                    await _hubsService.SendSessionOnGoingNotificationToUser(session.TutorId, tutorNotification);
                }
            }
        }