Beispiel #1
0
        public ViewModels.Lessons.View GenerateTokBoxToken(ViewModels.Lessons.View viewModel, int loggedInUserId, string loggedInUserEmail)
        {
            var opentok            = new OpenTok(Constants.TokBox.ApiKey, Constants.TokBox.ApiSecret);
            var connectionMetadata = "email=" + loggedInUserEmail + ";accid=" + loggedInUserId;

            if (viewModel.lesson.TokBoxSessionId != null)
            {
                viewModel.token = opentok.GenerateToken(viewModel.lesson.TokBoxSessionId, Role.PUBLISHER, 0, connectionMetadata);
            }
            else
            {
                using (var conn = new dbEntities())
                {
                    var session        = opentok.CreateSession("", MediaMode.ROUTED, ArchiveMode.MANUAL);
                    var currentLession = conn.Lessons.FirstOrDefault(l => l.ID == viewModel.lesson.ID);
                    if (currentLession != null)
                    {
                        currentLession.TokBoxSessionId = session.Id;
                        conn.SaveChanges();
                        viewModel.lesson = currentLession;
                    }
                    if (viewModel.lesson.TokBoxSessionId != null)
                    {
                        viewModel.token = opentok.GenerateToken(viewModel.lesson.TokBoxSessionId, Role.PUBLISHER, 0, connectionMetadata);
                    }
                }
            }

            return(viewModel);
        }
Beispiel #2
0
        public ViewModels.Lessons.View LoadView(int id, int loggedInUserId)
        {
            var ret = new ViewModels.Lessons.View()
            {
                account = Helpers.UserAccountInfo.GetAccount(loggedInUserId).account
            };

            using (var conn = new dbEntities())
            {
                ret.lesson = conn.Lessons.FirstOrDefault(l => l.ID == id);
                if (ret.lesson == null)
                {
                    throw new Exception("Lesson does not exist.");
                }

                ret.host = ret.lesson.Account;

                // timezone out for displaying
                ret.lesson.BookingDate = Rules.Timezone.ConvertFromUTC(ret.lesson.BookingDate);

                foreach (var attachment in ret.lesson.LessonAttachments.Select(a => new { a.ID, a.Title }).ToList())
                {
                    ret.attachments.Add(new Models.Lessons.Attachment()
                    {
                        ID    = attachment.ID,
                        Title = attachment.Title
                    });
                }

                ret.lessonResources = conn.LessonResources.Where(r => r.Lession_ID == id)
                                      .ToList();

                foreach (var participant in ret.lesson.LessonParticipants.ToList())
                {
                    var other = conn.Accounts.FirstOrDefault(a => a.ID == participant.Account_ID);
                    if (other != null)
                    {
                        ret.others.Add(other);
                    }
                }
            }

            return(ret);
        }