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 isTeacher = userprofile.Subscriptions.Any(it => !it.DeletedDate.HasValue && it.ClassRoomId == body.ClassRoomId && it.Role == UserProfile.AccountRole.Teacher); var now = _dateTime.GetCurrentTime(); var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now) || isTeacher; 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 }; }
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.GetMockStrinValue(), Description = message.GetMockStrinValue(), LessonId = lessonId.GetMockStrinValue(), UserProfileId = userprofile.GetMockStrinValue() }; var commentCtrl = ScenarioContext.Current.Get<CommentController>(); commentCtrl.Post(body); }