public void WhenUserProfileIdRemoveTheCommentInTheLessonOfClassRoom(string userprofileName, string commentId, string lessonId, string classRoomId) { var mockCommentRepo = ScenarioContext.Current.Get<Mock<ICommentRepository>>(); mockCommentRepo.Setup(it => it.UpsertComment(It.IsAny<Comment>())); var commentCtrl = ScenarioContext.Current.Get<CommentController>(); var body = new UpdateCommentRequest { ClassRoomId = classRoomId, LessonId = lessonId, UserProfileId = userprofileName, IsDelete = true }; commentCtrl.Put(commentId, body); }
public void Put(string id, UpdateCommentRequest body) { var areArgumentsValid = !string.IsNullOrEmpty(id) && body != null && !string.IsNullOrEmpty(body.ClassRoomId) && !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(id); if (selectedComment == null) return; var isCommentOwner = selectedComment.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase); if (!isCommentOwner) { 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) { selectedComment.DeletedDate = now; } else { if (string.IsNullOrEmpty(body.Description)) return; selectedComment.Description = body.Description; } _commentRepo.UpsertComment(selectedComment); }