public void WhenUserProfileIdCreateANewCommentWithAMessageIsInTheLessonOfClassRoom(string userprofile, string message, 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 body = new PostNewCommentRequest { ClassRoomId = classRoomId, Description = message, LessonId = lessonId, UserProfileId = userprofile }; var commentCtrl = ScenarioContext.Current.Get <CommentController>(); commentCtrl.Post(body); }
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 }); }