Exemplo n.º 1
0
        public PostNewCommentRespond Post(PostNewCommentRequest body)
        {
            var areArgumentsValid = body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.Description) &&
                                    !string.IsNullOrEmpty(body.LessonId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

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

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId, out userprofile);

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

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now);

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

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(body.UserProfileId, body.ClassRoomId);

            if (selectedUserActivity == null)
            {
                return(null);
            }

            var selectedLesson = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId == body.LessonId);

            if (selectedLesson == null)
            {
                return(null);
            }

            var id         = Guid.NewGuid().ToString();
            var newComment = new Comment
            {
                id                     = id,
                ClassRoomId            = body.ClassRoomId,
                CreatedByUserProfileId = body.UserProfileId,
                Description            = body.Description,
                LessonId               = body.LessonId,
                CreatedDate            = now,
                CreatorDisplayName     = userprofile.Name,
                CreatorImageUrl        = userprofile.ImageProfileUrl,
                Discussions            = Enumerable.Empty <Comment.Discussion>(),
            };

            _commentRepo.UpsertComment(newComment);

            selectedLesson.CreatedCommentAmount++;
            _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            _notificationCtrl.SendNotification();
            return(new PostNewCommentRespond {
                ActualCommentId = id
            });
        }
Exemplo n.º 2
0
        public PostNewDiscussionRespond Post(PostNewDiscussionRequest body)
        {
            var areArgumentsValid = body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.CommentId) &&
                                    !string.IsNullOrEmpty(body.Description) &&
                                    !string.IsNullOrEmpty(body.LessonId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

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

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId, out userprofile);

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

            var now       = _dateTime.GetCurrentTime();
            var isTeacher = userprofile.Subscriptions.Any(it => !it.DeletedDate.HasValue && it.ClassRoomId == body.ClassRoomId && it.Role == UserProfile.AccountRole.Teacher);
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now, isTeacher);

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

            var selectedComment = _commentRepo.GetCommentById(body.CommentId);
            var isCommentValid  = selectedComment != null &&
                                  selectedComment.LessonId.Equals(body.LessonId, StringComparison.CurrentCultureIgnoreCase) &&
                                  selectedComment.id.Equals(body.CommentId, StringComparison.CurrentCultureIgnoreCase) &&
                                  !selectedComment.DeletedDate.HasValue;

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

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(body.UserProfileId, body.ClassRoomId);
            var isUserActivityValid  = selectedUserActivity != null && !selectedUserActivity.DeletedDate.HasValue;

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

            var selectedLesson = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId == body.LessonId);

            if (selectedLesson == null)
            {
                return(null);
            }

            if (!isTeacher)
            {
                var isCommentOwner = selectedComment.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase);
                if (!isCommentOwner)
                {
                    var canPostNewDiscussion = _userprofileRepo.CheckAccessPermissionToUserProfile(selectedComment.CreatedByUserProfileId);
                    if (!canPostNewDiscussion)
                    {
                        return(null);
                    }
                }
            }

            var id            = Guid.NewGuid().ToString();
            var discussions   = selectedComment.Discussions.ToList();
            var newDiscussion = new Comment.Discussion
            {
                id = id,
                CreatedByUserProfileId = body.UserProfileId,
                CreatorDisplayName     = userprofile.Name,
                CreatorImageUrl        = userprofile.ImageProfileUrl,
                Description            = body.Description,
                CreatedDate            = now,
            };

            discussions.Add(newDiscussion);
            selectedComment.Discussions = discussions;
            _commentRepo.UpsertComment(selectedComment);

            selectedLesson.ParticipationAmount++;
            _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            _notificationCtrl.SendNotification();
            return(new PostNewDiscussionRespond {
                ActualCommentId = id
            });
        }
Exemplo n.º 3
0
        public LessonContentRespond Get(string id, string classRoomId, string userId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId) &&
                                    !string.IsNullOrEmpty(userId);

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

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(userId, classRoomId, out userprofile);

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

            var subscription = userprofile.Subscriptions
                               .Where(it => !it.DeletedDate.HasValue)
                               .Where(it => it.ClassRoomId.Equals(classRoomId, StringComparison.CurrentCultureIgnoreCase))
                               .FirstOrDefault();

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(classRoomId, id, now);

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

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);

            if (selectedClassRoom == null)
            {
                return(null);
            }

            var selectedLesson = selectedClassRoom.Lessons.FirstOrDefault(it => it.id.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLesson == null)
            {
                return(null);
            }

            var selectedLessonCatalog = _lessonCatalogRepo.GetLessonCatalogById(selectedLesson.LessonCatalogId);

            if (selectedLessonCatalog == null)
            {
                return(null);
            }

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(userId, classRoomId);

            if (selectedUserActivity == null)
            {
                return(null);
            }
            var selectedLessonActivity = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLessonActivity == null)
            {
                return(null);
            }

            var selectedSubscription = userprofile.Subscriptions.FirstOrDefault(it => it.ClassRoomId == classRoomId);

            if (selectedSubscription == null)
            {
                return(null);
            }
            selectedSubscription.LastActiveDate = now;
            _userprofileRepo.UpsertUserProfile(userprofile);

            var shouldUpdateSawPrimaryContent = !selectedLessonActivity.SawContentIds.Contains(selectedLessonCatalog.PrimaryContentURL);

            if (shouldUpdateSawPrimaryContent)
            {
                var sawList = selectedLessonActivity.SawContentIds.ToList();
                sawList.Add(selectedLessonCatalog.PrimaryContentURL);
                selectedLessonActivity.SawContentIds = sawList;
                _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            }

            var isTeacher           = subscription.Role == UserProfile.AccountRole.Teacher;
            var isDisplayTeacherMsg = selectedUserActivity.HideClassRoomMessageDate.HasValue ?
                                      selectedClassRoom.LastUpdatedMessageDate > selectedUserActivity.HideClassRoomMessageDate.Value :
                                      true;

            return(new LessonContentRespond
            {
                Advertisments = selectedLessonCatalog.Advertisments,
                CourseCatalogId = selectedLessonCatalog.CourseCatalogId,
                CreatedDate = selectedLessonCatalog.CreatedDate,
                ExtraContentUrls = selectedLessonCatalog.ExtraContentUrls,
                FullDescription = selectedLessonCatalog.FullDescription,
                FullTeacherLessonPlan = isTeacher ? selectedLessonCatalog.FullTeacherLessonPlan : string.Empty,
                id = id,
                Order = selectedLessonCatalog.Order,
                PrimaryContentURL = selectedLessonCatalog.PrimaryContentURL,
                SemesterName = selectedLessonCatalog.SemesterName,
                ShortDescription = selectedLessonCatalog.ShortDescription,
                ShortTeacherLessonPlan = isTeacher ? selectedLessonCatalog.ShortTeacherLessonPlan : string.Empty,
                Title = selectedLessonCatalog.Title,
                UnitNo = selectedLessonCatalog.UnitNo,
                CourseMessage = isDisplayTeacherMsg ? selectedClassRoom.Message : null,
                IsTeacher = isTeacher,
                TotalLikes = selectedLesson.TotalLikes
            });
        }
Exemplo n.º 4
0
        public GetLikeRespond GetLikes(string id, string classRoomId, string lessonId)
        {
            var invalidDataRespond = new GetLikeRespond
            {
                LessonId          = lessonId,
                LikeCommentIds    = Enumerable.Empty <string>(),
                LikeDiscussionIds = Enumerable.Empty <string>()
            };
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId) &&
                                    !string.IsNullOrEmpty(lessonId);

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

            var canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(id, classRoomId);

            if (!canAccessToTheClassRoom)
            {
                return(invalidDataRespond);
            }

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(classRoomId, lessonId, now);

            if (!canAccessToTheClassLesson)
            {
                return(invalidDataRespond);
            }

            var likeLessons = _likeLessonRepo.GetLikeLessonsByUserProfileIdAndLesson(id, lessonId);

            if (likeLessons == null)
            {
                return(invalidDataRespond);
            }
            var likeComments = _likeCommentRepo.GetLikeCommentsByUserProfileIdAndLesson(id, lessonId);

            if (likeComments == null)
            {
                return(invalidDataRespond);
            }
            var likeDiscussions = _likeDiscussionRepo.GetLikeDiscussionsByUserProfileIdAndLesson(id, lessonId);

            if (likeDiscussions == null)
            {
                return(invalidDataRespond);
            }

            var likeCommentIds    = likeComments.Where(it => !it.DeletedDate.HasValue).Select(it => it.CommentId).ToList();
            var likeDiscussionIds = likeDiscussions.Where(it => !it.DeletedDate.HasValue).Select(it => it.DiscussionId).ToList();

            return(new GetLikeRespond
            {
                LessonId = lessonId,
                IsLikedLesson = likeLessons.Any(it => !it.DeletedDate.HasValue),
                LikeCommentIds = likeCommentIds,
                LikeDiscussionIds = likeDiscussionIds
            });
        }
Exemplo n.º 5
0
        public LessonContentRespond Get(string id, string classRoomId, string userId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId) &&
                                    !string.IsNullOrEmpty(userId);

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

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(userId, classRoomId, out userprofile);

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

            var subscriptions = userprofile.Subscriptions
                                .Where(it => !it.DeletedDate.HasValue)
                                .Where(it => it.ClassRoomId.Equals(classRoomId, StringComparison.CurrentCultureIgnoreCase));

            if (!subscriptions.Any())
            {
                return(null);
            }
            var now       = _dateTime.GetCurrentTime();
            var isTeacher = subscriptions.Any(it => it.Role == UserProfile.AccountRole.Teacher);
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(classRoomId, id, now, isTeacher);

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

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);
            var isClassRoomValid  = selectedClassRoom != null && !selectedClassRoom.DeletedDate.HasValue;

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

            var selectedLesson = selectedClassRoom.Lessons.FirstOrDefault(it => it.id.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLesson == null)
            {
                return(null);
            }

            var selectedLessonCatalog = _lessonCatalogRepo.GetLessonCatalogById(selectedLesson.LessonCatalogId);

            if (selectedLessonCatalog == null)
            {
                return(null);
            }

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(userId, classRoomId);
            var isUserActivityValid  = selectedUserActivity != null && !selectedUserActivity.DeletedDate.HasValue;

            if (!isUserActivityValid)
            {
                return(null);
            }
            var selectedLessonActivity = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLessonActivity == null)
            {
                return(null);
            }

            var selectedSubscription = userprofile.Subscriptions.FirstOrDefault(it => it.ClassRoomId == classRoomId);

            if (selectedSubscription == null)
            {
                return(null);
            }
            selectedSubscription.LastActiveDate = now;
            _userprofileRepo.UpsertUserProfile(userprofile);

            var shouldUpdateSawPrimaryContent = !selectedLessonActivity.SawContentIds.Contains(selectedLessonCatalog.id);

            if (shouldUpdateSawPrimaryContent)
            {
                var sawList = selectedLessonActivity.SawContentIds.ToList();
                sawList.Add(selectedLessonCatalog.id);
                selectedLessonActivity.SawContentIds = sawList;
                _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            }

            var isDisplayTeacherMsg = selectedUserActivity.HideClassRoomMessageDate.HasValue ?
                                      selectedClassRoom.LastUpdatedMessageDate > selectedUserActivity.HideClassRoomMessageDate.Value :
                                      true;

            var result = new LessonContentRespond
            {
                id              = id,
                Order           = selectedLessonCatalog.Order,
                SemesterName    = selectedLessonCatalog.SemesterName,
                UnitNo          = selectedLessonCatalog.UnitNo,
                CourseCatalogId = selectedLessonCatalog.CourseCatalogId,
                Title           = selectedLessonCatalog.Title,
                CreatedDate     = selectedLessonCatalog.CreatedDate,
                Advertisments   = selectedLessonCatalog.Advertisments,
                CourseMessage   = isDisplayTeacherMsg ? selectedClassRoom.Message : null,
                IsTeacher       = isTeacher,
                TotalLikes      = selectedLesson.TotalLikes,
                StudentItems    = selectedLessonCatalog.StudentItems ?? Enumerable.Empty <LessonCatalog.LessonItem>(),
                TeacherItems    = selectedLessonCatalog.TeacherItems ?? Enumerable.Empty <LessonCatalog.LessonItem>(),
                PostAssessments = selectedLessonCatalog.PostAssessments ?? Enumerable.Empty <LessonCatalog.AssessmentItem>(),
                PreAssessments  = selectedLessonCatalog.PreAssessments ?? Enumerable.Empty <LessonCatalog.AssessmentItem>(),
            };

            result.StudentItems    = result.StudentItems.OrderBy(it => it.Order);
            result.TeacherItems    = result.TeacherItems.OrderBy(it => it.Order);
            result.PostAssessments = result.PostAssessments.OrderBy(it => it.Order);
            result.PreAssessments  = result.PreAssessments.OrderBy(it => it.Order);
            return(result);
        }