示例#1
0
        public IEnumerable <CourseMapContentRespond> Get(string id, string classRoomId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId);

            if (!areArgumentsValid)
            {
                return(Enumerable.Empty <CourseMapContentRespond>());
            }

            if (!_userprofileRepo.CheckAccessPermissionToSelectedClassRoom(id, classRoomId))
            {
                return(Enumerable.Empty <CourseMapContentRespond>());
            }

            var now                     = _dateTime.GetCurrentTime();
            var classCalendar           = _classCalendarRepo.GetClassCalendarByClassRoomId(classRoomId);
            var canAccessToTheClassRoom = classCalendar != null &&
                                          classCalendar.LessonCalendars != null &&
                                          !classCalendar.DeletedDate.HasValue &&
                                          !classCalendar.CloseDate.HasValue &&
                                          classCalendar.ExpiredDate.HasValue &&
                                          classCalendar.ExpiredDate.Value.Date > now.Date;

            if (!canAccessToTheClassRoom)
            {
                return(Enumerable.Empty <CourseMapContentRespond>());
            }

            var result = classCalendar.LessonCalendars
                         .Where(it => !it.DeletedDate.HasValue)
                         .GroupBy(it => it.SemesterGroupName)
                         .Select(group => new CourseMapContentRespond
            {
                SemesterName = group.Key,
                LessonStatus = group.Select(it => new CourseMapLessonStatus
                {
                    LessonId       = it.LessonId,
                    IsLocked       = now.Date < it.BeginDate.Date,
                    LessonWeekName = string.Format("Week{0:00}", it.Order),
                }).ToList()
            }).ToList();
            var lessonQry     = result.SelectMany(it => it.LessonStatus);
            var currentLesson = lessonQry.LastOrDefault(it => !it.IsLocked);

            if (currentLesson != null)
            {
                currentLesson.IsCurrent = true;
            }
            else if (lessonQry.Any())
            {
                lessonQry.Last().IsCurrent = true;
            }
            return(result);
        }
示例#2
0
        public static bool CheckAccessPermissionToSelectedClassLesson(this IClassCalendarRepository classCalendarRepo, string classRoomId, string lessonId, DateTime currentTime, bool isTeacher = false)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(classRoomId) && !string.IsNullOrEmpty(lessonId);

            if (!areArgumentsValid)
            {
                return(false);
            }

            var selectedClassCalendar = classCalendarRepo.GetClassCalendarByClassRoomId(classRoomId);
            var isClassCalendarValid  = selectedClassCalendar != null && !selectedClassCalendar.DeletedDate.HasValue;

            if (!isClassCalendarValid)
            {
                return(false);
            }

            var canAccessToTheLesson = selectedClassCalendar.LessonCalendars
                                       .Where(it => !it.DeletedDate.HasValue)
                                       .Where(it => it.LessonId.Equals(lessonId, StringComparison.CurrentCultureIgnoreCase))
                                       .Where(it => isTeacher || it.BeginDate <= currentTime)
                                       .Any();

            return(canAccessToTheLesson);
        }
示例#3
0
        /// <summary>
        /// Find the user's last activate course and navigate user to that course
        /// </summary>
        public IActionResult Preparing()
        {
            var userprofile = _userprofileRepo.GetUserProfileById(User.Identity.Name);

            if (userprofile == null)
            {
                _logger.LogCritical($"User profile { User.Identity.Name } not found.");
                ViewBag.ErrorMessage = _errorMsgs.AccountNotFound;
                return(View("Error"));
            }

            var lastActiveSubscription = userprofile.Subscriptions
                                         .Where(it => !it.DeletedDate.HasValue)
                                         .Where(it => it.LastActiveDate.HasValue)
                                         .OrderByDescending(it => it.LastActiveDate)
                                         .FirstOrDefault();
            var isAnyActivatedSubscription = lastActiveSubscription != null;

            if (!isAnyActivatedSubscription)
            {
                ViewBag.ErrorMessage = _errorMsgs.NoLastActivatedCourse;
                return(View("Error"));
            }

            var classCalendar        = _classCalendarRepo.GetClassCalendarByClassRoomId(lastActiveSubscription.ClassRoomId);
            var isClassCalendarValid = classCalendar != null && classCalendar.LessonCalendars != null && classCalendar.LessonCalendars.Any(it => !it.DeletedDate.HasValue);

            if (!isClassCalendarValid)
            {
                ViewBag.ErrorMessage = _errorMsgs.EntireCourseIsIncomplete;
                return(View("Error"));
            }

            var now = _dateTime.GetCurrentTime();
            var currentLessonCalendar = classCalendar.LessonCalendars
                                        .Where(it => !it.DeletedDate.HasValue)
                                        .Where(it => now.Date >= it.BeginDate)
                                        .OrderByDescending(it => it.BeginDate)
                                        .FirstOrDefault() ?? classCalendar.LessonCalendars.OrderBy(it => it.BeginDate).FirstOrDefault();
            var isCurrentLessonValid = currentLessonCalendar != null;

            if (!isCurrentLessonValid)
            {
                ViewBag.ErrorMessage = _errorMsgs.EntireCourseIsIncomplete;
                return(View("Error"));
            }

            var redirectURL = $"/my#!/app/main/lesson/{ currentLessonCalendar.LessonId }/{ lastActiveSubscription.ClassRoomId }";

            return(Redirect(redirectURL));
        }
        public GetUserProfileRespond Get(string id)
        {
            var isArgumentValid = !string.IsNullOrEmpty(id);

            if (!isArgumentValid)
            {
                return(null);
            }

            var userprofile = _userProfileRepo.GetUserProfileById(id);

            if (userprofile == null)
            {
                return(null);
            }
            var currentUser = System.Security.Claims.PrincipalExtensions.GetUserId(HttpContext.User);
            var user        = _userManager.FindByIdAsync(currentUser).Result;
            var isUserProfileSubscriptionValid = userprofile.Subscriptions != null && userprofile.Subscriptions.Any(it => it.LastActiveDate.HasValue);
            var userProfileInfo = new GetUserProfileRespond
            {
                UserProfileId      = userprofile.id,
                HasPassword        = _userManager.HasPasswordAsync(user).Result,
                FullName           = userprofile.Name,
                ImageUrl           = userprofile.ImageProfileUrl,
                SchoolName         = userprofile.SchoolName,
                IsPrivateAccout    = userprofile.IsPrivateAccount,
                IsReminderOnceTime = userprofile.CourseReminder == UserProfile.ReminderFrequency.Once
            };

            if (!isUserProfileSubscriptionValid)
            {
                return(userProfileInfo);
            }

            var lastActiveSubscription = userprofile.Subscriptions
                                         .Where(it => it.LastActiveDate.HasValue)
                                         .OrderByDescending(it => it.LastActiveDate)
                                         .FirstOrDefault();

            userProfileInfo.CurrentClassRoomId = lastActiveSubscription.ClassRoomId;
            var classCalendar        = _classCalendarRepo.GetClassCalendarByClassRoomId(lastActiveSubscription.ClassRoomId);
            var isClassCalendarValid = classCalendar != null && classCalendar.LessonCalendars != null && classCalendar.LessonCalendars.Any();

            if (!isClassCalendarValid)
            {
                return(userProfileInfo);
            }

            var now = _dateTime.GetCurrentTime();
            var lessonCalendarQry = classCalendar.LessonCalendars.Where(it => !it.DeletedDate.HasValue);

            var currentLesson = lessonCalendarQry.Where(it => now.Date >= it.BeginDate).OrderByDescending(it => it.BeginDate).FirstOrDefault();

            if (currentLesson == null)
            {
                return(userProfileInfo);
            }
            else
            {
                userProfileInfo.CurrentLessonId = currentLesson.LessonId;
                userProfileInfo.CurrentLessonNo = currentLesson.Order;
            }

            return(userProfileInfo);
        }