Ejemplo n.º 1
0
        public void WhenUserProfileIdRemoveTheDiscussionFromCommentInTheLessonOfClassRoom(string userprofileId, string discussionId, string commentId, string lessonId, string classRoomId)
        {
            var mockCommentRepo = ScenarioContext.Current.Get <Mock <ICommentRepository> >();

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

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

            discussionCtrl.Put(discussionId, body);
        }
Ejemplo n.º 2
0
        public void Put(string id, UpdateDiscussionRequest body)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.CommentId) &&
                                    !string.IsNullOrEmpty(body.LessonId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

            if (!areArgumentsValid)
            {
                return;
            }

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

            if (!canAccessToTheClassRoom)
            {
                return;
            }

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

            if (!canAccessToTheClassLesson)
            {
                return;
            }

            var selectedComment = _commentRepo.GetCommentById(body.CommentId);

            if (selectedComment == null)
            {
                return;
            }
            var selectedDiscussion = selectedComment.Discussions.FirstOrDefault(it => it.id.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedDiscussion == null)
            {
                return;
            }

            var canUpsertTheDiscussion = selectedComment.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase) ||
                                         selectedDiscussion.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase);

            if (!canUpsertTheDiscussion)
            {
                var isTeacher = (bool)userprofile.Subscriptions?.Any(it => !it.DeletedDate.HasValue && it.ClassRoomId == body.ClassRoomId && it.Role == UserProfile.AccountRole.Teacher);
                if (!isTeacher)
                {
                    return;
                }
            }

            if (body.IsDelete)
            {
                selectedDiscussion.DeletedDate = now;
            }
            else
            {
                if (string.IsNullOrEmpty(body.Description))
                {
                    return;
                }
                selectedDiscussion.Description = body.Description;
            }
            _commentRepo.UpsertComment(selectedComment);
        }