Exemple #1
0
        public void WhenUserProfileIdCreateANewDiscussionWithAMessageIsForCommentInTheLessonOfClassRoom(string userprofileId, string message, string commentId, string lessonId, string classRoomId)
        {
            var mockCommentRepo = ScenarioContext.Current.Get <Mock <ICommentRepository> >();

            mockCommentRepo.Setup(it => it.UpsertComment(It.IsAny <Comment>()));

            var mockUserActivityRepo = ScenarioContext.Current.Get <Mock <IUserActivityRepository> >();

            mockUserActivityRepo.Setup(it => it.UpsertUserActivity(It.IsAny <UserActivity>()));

            var discussionCtrl = ScenarioContext.Current.Get <DiscussionController>();
            var body           = new PostNewDiscussionRequest
            {
                ClassRoomId   = classRoomId,
                CommentId     = commentId,
                Description   = message,
                LessonId      = lessonId,
                UserProfileId = userprofileId
            };

            discussionCtrl.Post(body);
        }
Exemple #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
            });
        }