public ActionResult CreatePost(PostViewModel postModel, UserViewModel userModel) { MembershipUser currentUser = Membership.GetUser(); userModel.Email = currentUser.UserName; userService.GetUserByEmail(userModel.Email); postModel.AuthorId = userService.GetUserByEmail(userModel.Email).UserId; postService.CreatePost(postModel.ToBllPost()); return(RedirectToAction("UserPost")); }
public void Post([FromBody] PostViewModel post) { if (ModelState.IsValid) { PostViewModel model = new PostViewModel { Text = post.Text, CreatedOn = DateTime.Now, Name = post.Name }; postService.CreatePost(model.ToBllPost()); } }
public ActionResult CreatePost(PostViewModel post) { if (!ModelState.IsValid) { return(View(post)); } PostViewModel model = new PostViewModel { Text = post.Text, CreatedOn = DateTime.Now, Name = post.Name }; postService.CreatePost(model.ToBllPost()); return(RedirectToAction("")); }
public ActionResult EditPost(PostViewModel postModel, int id = 0) { var post = postModel.ToBllPost(); var oldPost = postService.GetPostEntity(id); post.Id = oldPost.Id; post.AuthorId = oldPost.AuthorId; post.AuthorLogin = oldPost.AuthorLogin; post.DateOfPost = oldPost.DateOfPost; post.PostMessage = oldPost.PostMessage; if (post.Body == null) { post.Body = oldPost.Body; } if (post.Name == null) { post.Name = oldPost.Name; } postService.Update(post); return(View(post.ToMvcPost())); }