public IActionResult Create(int postId) { var postCommentViewModel = this.postService.PostById(postId); PostCommentCreateModel postCommentCreateModel = Mapper.Map <PostCommentCreateModel>(postCommentViewModel); return(this.ViewOrNotFound(postCommentCreateModel)); }
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")); }
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() })); }
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)); }
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>(); }
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>(); }