コード例 #1
0
        public IActionResult Create(int postId)
        {
            var postCommentViewModel = this.postService.PostById(postId);

            PostCommentCreateModel postCommentCreateModel = Mapper.Map <PostCommentCreateModel>(postCommentViewModel);

            return(this.ViewOrNotFound(postCommentCreateModel));
        }
コード例 #2
0
        public IActionResult Create(PostCommentCreateModel model, string returnUrl = null)
        {
            if (CoreValidator.CheckIfStringIsNullOrEmpty(model.CommentText))
            {
                ModelState.AddModelError(string.Empty, "You cannot submit an empty comment!");
                return(this.ViewOrNotFound(model));
            }

            this.commentService.Create(model.CommentText, User.GetUserId(), model.Id);
            return(RedirectToAction("Index", "Users"));
        }
コード例 #3
0
        public ActionResult Create(PostCommentCreateModel model, string returnUrl = null)
        {
            if (String.IsNullOrEmpty(model.CommentText))
            {
                ModelState.AddModelError(string.Empty, "You cannot submit an empty comment!");
                return(View(model));
            }

            this.commentService.Create(model.CommentText, User.Identity.GetUserId(), model.Id);

            return(RedirectToAction("AccountDetails", "Users", new { id = this.User.Identity.GetUserId() }));
        }
コード例 #4
0
        public ActionResult Create(int id)  //id = postId
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <PostModel, PostCommentCreateModel>()
                .ForMember(p => p.Photo, c => c.MapFrom(p => p.Photo.ToRenderablePictureString()))
                .ForMember(p => p.UserProfilePicture, c => c.MapFrom(p => p.UserProfilePicture.ToRenderablePictureString()));
            });
            IMapper iMapper = config.CreateMapper();

            var postCommentViewModel = this.postService.PostById(id);

            PostCommentCreateModel postCommentCreateModel = iMapper.Map <PostModel, PostCommentCreateModel>(postCommentViewModel);

            return(View(postCommentCreateModel));
        }
コード例 #5
0
        public void CheckIfCreateMethodReturnsRedirectWhenOk()
        {
            //Arrange
            var postService    = MockCreator.PostServiceMock();
            var commentService = MockCreator.CommentServiceMock();

            var controller = new CommentController(postService.Object, commentService.Object);

            var model = new PostCommentCreateModel
            {
                CommentText = "Test"
            };

            //Act
            var result = controller.Create(model, null);

            //Assert
            result
            .Should()
            .BeOfType <RedirectToActionResult>();
        }
コード例 #6
0
        public void CheckIfCreateMethodReturnsViewWithErrorWhenModelTextIsEmpty()
        {
            //Arrange
            var postService    = MockCreator.PostServiceMock();
            var commentService = MockCreator.CommentServiceMock();

            var controller = new CommentController(postService.Object, commentService.Object);

            var model = new PostCommentCreateModel
            {
                CommentText = ""
            };

            //Act
            var result = controller.Create(model, null);

            //Assert
            result
            .Should()
            .BeOfType <ViewResult>();
        }