예제 #1
0
        public static IEnumerable<MeetingViewModel> GetCurrentUserMeetings2(bool showJustFutureMeetings, ApplicationUser user, ApplicationDbContext context, int utcOffset)
        {

            var meetingDtos = new List<MeetingViewModel>();
            var enrollmentsWithThisUser = context.Courses.SelectMany(u => u.Enrollments.Where(e => e.ApplicationUserId == user.Id));

            foreach (var enrollment in enrollmentsWithThisUser)
            {
                //Get all meetings with this enrollment where its cohort has a meeting that is in the future
                Enrollment enrollment1 = enrollment;
                var cohortMeetings = context.Meetings.Where(m => m.CourseId == enrollment1.CourseId);
                foreach (var meeting in cohortMeetings)
                {
                    var meetingToAdd = new MeetingViewModel
                    {
                        Id = meeting.Id,
                        Title = meeting.Title,
                        Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
                        End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
                        Description = meeting.Description,
                        IsAllDay = meeting.IsAllDay,
                        RecurrenceRule = meeting.RecurrenceRule,
                        RecurrenceException = meeting.RecurrenceException,
                        RecurrenceId = meeting.RecurrenceId,
                        CourseId = meeting.CourseId,
                        GtmUrl = meeting.GtmUrl
                    };
                    meetingDtos.Add(meetingToAdd);
                }
            }
            //foreach (var meeting in privateMeetings)
            //{
            //    var meetingToAdd = new MeetingViewModel()
            //    {
            //        Id = meeting.Id,
            //        Title = meeting.Title,
            //        Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
            //        End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
            //        Description = meeting.Description,
            //        IsAllDay = meeting.IsAllDay,
            //        RecurrenceRule = meeting.RecurrenceRule,
            //        RecurrenceException = meeting.RecurrenceException,
            //        RecurrenceId = meeting.RecurrenceId,
            //        CourseId = meeting.CourseId
            //    };
            //    meetingDtos.Add(meetingToAdd);
            //};
            return meetingDtos;
        }
예제 #2
0
        public static IEnumerable<MeetingViewModel> GetAllMeetings(ApplicationDbContext context, int utcOffset)
        {

            var meetingDtos = new List<MeetingViewModel>();
            //var cohortMeetings = context.Courses.SelectMany(u => u.Meetings.Where(m => m.CourseId > 0));

            //foreach (var meeting in cohortMeetings)
            //{
            //    var meetingToAdd = new MeetingViewModel
            //    {
            //        Id = meeting.Id,
            //        Title = meeting.Title,
            //        Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
            //        End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
            //        Description = meeting.Description,
            //        IsAllDay = meeting.IsAllDay,
            //        RecurrenceRule = meeting.RecurrenceRule,
            //        RecurrenceException = meeting.RecurrenceException,
            //        RecurrenceId = meeting.RecurrenceId,
            //        CourseId = meeting.CourseId,
            //        GtmUrl = meeting.GtmUrl
            //    };
            //    meetingDtos.Add(meetingToAdd);
            //}

            var privateMeetings = context.Meetings.Where(m => !String.IsNullOrEmpty(m.StudentId) && !String.IsNullOrEmpty(m.StudentId));

            foreach (var meeting in privateMeetings)
            {
                var meetingToAdd = new MeetingViewModel
                {
                    Id = meeting.Id,
                    Title = meeting.Title,
                    Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
                    End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
                    Description = meeting.Description,
                    IsAllDay = meeting.IsAllDay,
                    RecurrenceRule = meeting.RecurrenceRule,
                    RecurrenceException = meeting.RecurrenceException,
                    RecurrenceId = meeting.RecurrenceId,
                    CourseId = meeting.CourseId
                };
                meetingDtos.Add(meetingToAdd);
            }
            return meetingDtos;
        }
예제 #3
0
        private static void AddAllUserCohortMeetings(ApplicationDbContext context, ApplicationUser user, int utcOffset, ref List<MeetingViewModel> meetingDtos)
        {
            var enrollmentsWithThisUser = context.Courses.SelectMany(u => u.Enrollments.Where(e => e.ApplicationUserId == user.Id));

            foreach (var enrollment in enrollmentsWithThisUser)
            {
                //Get all meetings with this enrollment where its cohort has a meeting that is in the future
                Enrollment enrollment1 = enrollment;
                var cohortMeetings = context.Meetings.Where(m => m.CourseId == enrollment1.CourseId);
                foreach (var meeting in cohortMeetings)
                {
                    var meetingToAdd = new MeetingViewModel
                    {
                        Id = meeting.Id,
                        Title = meeting.Title,
                        Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
                        End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
                        Description = meeting.Description,
                        IsAllDay = meeting.IsAllDay,
                        RecurrenceRule = meeting.RecurrenceRule,
                        RecurrenceException = meeting.RecurrenceException,
                        RecurrenceId = meeting.RecurrenceId,
                        CourseId = meeting.CourseId,
                        GtmUrl = meeting.GtmUrl
                    };
                    meetingDtos.Add(meetingToAdd);
                }
            }
        }
        public ActionResult Update_MyAvailableTime([DataSourceRequest]DataSourceRequest request, MeetingViewModel task)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ApplicationDbContext())
                {
                    // Create a new Task entity and set its properties from the posted TaskViewModel
                    var entity = new Meeting
                    {
                        Id = task.Id,
                        Title = task.Title,
                        Start = task.Start,
                        End = task.End,
                        Description = task.Description,
                        RecurrenceRule = task.RecurrenceRule,
                        RecurrenceException = task.RecurrenceException,
                        RecurrenceId = task.RecurrenceId,
                        IsAllDay = task.IsAllDay,
                        InstructorId = task.InstructorId,
                        MeetingTypeId = task.MeetingTypeId
                    };
                    // Attach the entity
                    context.Meetings.Attach(entity);
                    // Change its state to Modified so Entity Framework can update the existing task instead of creating a new one
                    context.Entry(entity).State = EntityState.Modified;
                    // Update the entity in the database
                    try
                    {
                        // Insert the entity in the database
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {

                        Log4NetHelper.Log("Error Updating Available Meeting Available Meeting", LogLevel.ERROR, "MeetingsServices", 497, "tester", ex);
                    }
                }
            }
            // Return the updated task. Also return any validation errors.
            return Json(new[] { task }.ToDataSourceResult(request, ModelState));
        }
 public ActionResult Destroy_MyAvailableTime([DataSourceRequest]DataSourceRequest request, MeetingViewModel task)
 {
     if (ModelState.IsValid)
     {
         using (var context = new ApplicationDbContext())
         {
             // Create a new Task entity and set its properties from the posted TaskViewModel
             var meeting = new Meeting
             {
                 Id = task.Id,
                 Title = task.Title,
                 Start = task.Start,
                 End = task.End,
                 Description = task.Description,
                 RecurrenceRule = task.RecurrenceRule,
                 RecurrenceException = task.RecurrenceException,
                 RecurrenceId = task.RecurrenceId,
                 IsAllDay = task.IsAllDay,
                 InstructorId = task.InstructorId
             };
             context.Meetings.Attach(meeting);
             context.Meetings.Remove(meeting);
             context.SaveChanges();
         }
     }
     // Return the removed task. Also return any validation errors.
     return Json(new[] { task }.ToDataSourceResult(request, ModelState));
 }
        public ActionResult Read_My_Booked_And_All_Available_Meetings([DataSourceRequest] DataSourceRequest request)
        {
            var meetingDtos = new List<MeetingViewModel>();
            var utcOffset = 0;
            var userId = _currentUser.User.Id;
            var privateMeetings = _context.Meetings.Where(m => m.StudentId == userId ||
                                                            m.InstructorId == userId ||
                                                            m.Course.Enrollments.Any(e => e.ApplicationUserId == userId) ||
                                                            m.MeetingTypeId == (int)MeetingType.Available).ToList();
            //var privateMeetings = _context.Meetings.Where(m => m.Course.Enrollments.Any(e => e.ApplicationUserId == userId ||
            //                                               m.MeetingTypeId == (int)MeetingType.Available)).ToList();

            foreach (var meeting in privateMeetings)
            {
                var meetingToAdd = new MeetingViewModel
                {
                    Id = meeting.Id,
                    Title = meeting.Title,
                    Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
                    End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
                    Description = meeting.Description,
                    IsAllDay = meeting.IsAllDay,
                    RecurrenceRule = meeting.RecurrenceRule,
                    RecurrenceException = meeting.RecurrenceException,
                    RecurrenceId = meeting.RecurrenceId,
                    CourseId = meeting.CourseId,
                    MeetingTypeId = meeting.MeetingTypeId
                };
                meetingDtos.Add(meetingToAdd);
            }
            return Json(meetingDtos.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        //public ActionResult Read_My_Booked_And_Available_Meetings([DataSourceRequest] DataSourceRequest request)
        //{
        //    IEnumerable<MeetingViewModel> myMeetings = MeetingsServices.Get_MyBooked_And_Available_Meetings(_currentUser.User.Id, _context);
        //    return Json(myMeetings.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        //}



        public ActionResult Create_MyAvailableTime([DataSourceRequest]DataSourceRequest request, MeetingViewModel meeting)
        {
            if (ModelState.IsValid)
            {
                var newMeeting = MeetingsServices.CreateMyAvailableTime(meeting, _currentUser.User.Id);
                // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors.
                return Json(new[] { newMeeting }.ToDataSourceResult(request, ModelState));
            }
            return null;

        }
        public ActionResult CreateCourseMeeting([DataSourceRequest]DataSourceRequest request, MeetingViewModel meetingViewModel)
        {
            var course = _context.Courses.Include(c => c.CourseTemplate).Include(c => c.Enrollments).FirstOrDefault(c => c.Id == meetingViewModel.CourseId);
            if (course == null)
                return null;

            var courseTitle = MeetingsServices.GetCourseTitle(course);

            if (ModelState.IsValid)
            {
                var joinUrl = MeetingsServices.CreateGtmForMeeting(_context, meetingViewModel);
                if (String.IsNullOrEmpty(joinUrl))
                    RedirectToAction("oops", "Home", new { area = "" });

                var newMeeting = MeetingsServices.CreateMeetingforGtm(meetingViewModel, courseTitle, joinUrl, _currentUser.User);
                var instructor = _currentUser.User;
                MeetingsServices.SendMeetingNotifications(course, newMeeting, _emailService, _context, instructor);
            }
            // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors.
            return Json(new[] { meetingViewModel }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult MyAvailableTimes()
        {
            ViewBag.UtcOffset = TimeDateServices.GetUtcOffSet();

            var vm = new MeetingViewModel
            {
                Title = _currentUser!=null ? _currentUser.User.FirstName + " " + _currentUser.User.LastName.Substring(0, 1) + "." : ""
            };
            return PartialView(vm);
        }
예제 #10
0
        public static Meeting CreateMeetingforGtm(MeetingViewModel meeting, string courseTitle, string joinUrl,
            ApplicationUser instructor)
        {
            using (var context = new ApplicationDbContext())
            {
                //Create a new Task entity and set its properties from the posted TaskViewModel
                var newMeeting = new Meeting
                {
                    Title = meeting.Title,
                    Start = meeting.Start,
                    End = meeting.End,
                    Description = meeting.Description,
                    RecurrenceRule = meeting.RecurrenceRule,
                    RecurrenceException = meeting.RecurrenceException,
                    RecurrenceId = meeting.RecurrenceId,
                    IsAllDay = false,
                    CourseId = meeting.CourseId,
                    GtmUrl = joinUrl,
                    InstructorId = instructor.Id,
                    MeetingTypeId = (int) MeetingType.ClassMeeting,
                    StudentId = instructor.Id
                };

                try
                {
                    context.Meetings.Add(newMeeting);
                    context.SaveChanges();
                }
                    //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    //{
                    //    //Exception raise = dbEx;
                    //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    //    {
                    //        foreach (var validationError in validationErrors.ValidationErrors)
                    //        {
                    //            string errorMessage = string.Format("{0}:{1}",
                    //                validationErrors.Entry.Entity.ToString(),
                    //                validationError.ErrorMessage);
                    //            // raise a new exception nesting
                    //            // the current instance as InnerException
                    //            //raise = new InvalidOperationException(errorMessage, raise);
                    //        }
                    //    }
                    //    Log4NetHelper.Log("Did not save new Class Meeting - Validation Error", LogLevel.ERROR, "MeetingServices", 585, "tester", dbEx);
                    //}


                catch (Exception ex)
                {
                    Log4NetHelper.Log("Did not save new Class Meeting", LogLevel.ERROR, "MeetingServices", 585, "tester",
                        ex);
                }

                // Get the TaskID generated by the database
                meeting.Id = newMeeting.Id;

                return newMeeting;
            }
        }
예제 #11
0
        public static string CreateGtmForMeeting(ApplicationDbContext context, MeetingViewModel meeting)
        {
            var gtmKeySet = context.GtmKeySets.First();
            var userId = gtmKeySet.Email;
            var password = gtmKeySet.EmailPassword;
            var oauthToken = "";

            // a request to login is created and sent. From the response
            // we need to store at least the access token to use for further calls

            var meetingRequestUri = new RequestDirectLogin(gtmKeySet.ConsumerKey, userId, password);
            string output;
            var resp = meetingRequestUri.Send(out output);

            if (resp != null)
                oauthToken = resp.AccessToken;

            var meetingsApi = new MeetingsApi();
            var newMeeting = new MeetingReqCreate
            {
                subject = meeting.Title,
                starttime = meeting.Start,
                endtime = meeting.End,
                passwordrequired = false,
                conferencecallinfo = "Hybrid",
                timezonekey = "",
                meetingtype = MeetingReqCreate.MeetingtypeEnum.scheduled
            };
            try
            {
                var meetingCreated = meetingsApi.createMeeting(oauthToken, newMeeting);
                return meetingCreated.First().joinURL;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Log4NetHelper.Log("Ceate Gtm Failed", LogLevel.ERROR, "CreateGtmForMeeting", 241, "Tester", ex);
                return "";
            }
        }
예제 #12
0
        public static IEnumerable<MeetingViewModel> Get_MyBooked_And_Available_Meetings(string userId,
            ApplicationDbContext context)
        {
            var utcOffset = TimeDateServices.GetUtcOffSet();
            ICollection<MeetingViewModel> allMeetings = new List<MeetingViewModel>();
            var privateMeetings = context.Meetings.Where(m => m.StudentId == userId || m.InstructorId == userId);
            foreach (var meeting in privateMeetings)
            {
                var meetingToAdd = new MeetingViewModel
                {
                    Id = meeting.Id,
                    Title = meeting.Title,
                    Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
                    End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
                    Description = meeting.Description,
                    IsAllDay = meeting.IsAllDay,
                    RecurrenceRule = meeting.RecurrenceRule,
                    RecurrenceException = meeting.RecurrenceException,
                    RecurrenceId = meeting.RecurrenceId,
                    CourseId = meeting.CourseId
                };
                allMeetings.Add(meetingToAdd);
            }

            return allMeetings;
        }
예제 #13
0
        public static Meeting CreateMyAvailableTime(MeetingViewModel meeting, string currentUserId)
        {
            using (var context = new ApplicationDbContext())
            {
                //Create a new Task entity and set its properties from the posted TaskViewModel
                var entity = new Meeting
                {
                    Id = meeting.Id,
                    Title = meeting.Title,
                    Start = meeting.Start,
                    End = meeting.End,
                    Description = meeting.Description,
                    RecurrenceRule = meeting.RecurrenceRule,
                    RecurrenceException = meeting.RecurrenceException,
                    RecurrenceId = meeting.RecurrenceId,
                    IsAllDay = meeting.IsAllDay,
                    InstructorId = currentUserId,
                    MeetingTypeId = Convert.ToInt32(MeetingType.Available)
                };


                // Add the entity
                context.Meetings.Add(entity);
                try
                {
                    // Insert the entity in the database
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Log4NetHelper.Log("Choked Creating new Available Meeting", LogLevel.ERROR, "MeetingsServices", 497,
                        "tester", ex);
                }

                // Get the TaskID generated by the database
                meeting.Id = entity.Id;

                return entity;
            }
        }
예제 #14
0
 public static IEnumerable<MeetingViewModel> Read_MyMeetings(ApplicationUser user, ApplicationDbContext context)
 {
     var meetingDtos = new List<MeetingViewModel>();
     var utcOffset = 0;
     var privateMeetings =
         context.Meetings.Where(
             m =>
                 m.StudentId == user.Id || m.InstructorId == user.Id && m.StudentId != null ||
                 m.Course.Enrollments.Any(e => e.ApplicationUserId == user.Id));
     foreach (var meeting in privateMeetings)
     {
         var meetingToAdd = new MeetingViewModel
         {
             Id = meeting.Id,
             Title = meeting.Title,
             Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
             End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
             Description = meeting.Description,
             IsAllDay = meeting.IsAllDay,
             RecurrenceRule = meeting.RecurrenceRule,
             RecurrenceException = meeting.RecurrenceException,
             RecurrenceId = meeting.RecurrenceId,
             CourseId = meeting.CourseId,
             MeetingTypeId = meeting.MeetingTypeId
         };
         meetingDtos.Add(meetingToAdd);
     }
     return meetingDtos;
 }