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 canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now); if (!canAccessToTheClassLesson) return null; var selectedComment = _commentRepo.GetCommentById(body.CommentId); if (selectedComment == null) 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 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 }; }
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); }