// POST api/post public IHttpActionResult Post(PostBindingModel post) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var postedBy = _userRepository.FindById(User.Identity.GetUserId()); var model = new Post() { Message = post.Message, PostedBy = postedBy.Id, PostedOn = DateTime.UtcNow, LikedBy = new List<string>(), Comments = new List<Comment>() }; model.PostedBy = User.Identity.GetUserId(); _postRepository.Insert(model); var vModel = new PostViewModel { Id = model.Id, Message = post.Message, PostedBy = AutoMapper.Mapper.Map<ApplicationUser, ApplicationUserViewModel>(postedBy), LikeCount = model.LikeCount, LikedBy = new List<ApplicationUserViewModel>(), Comments = new List<CommentViewModel>() }; return Ok(vModel); }
// PUT api/post/5 public IHttpActionResult Put(PostBindingModel post) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var postModel = AutoMapper.Mapper.Map<PostBindingModel, Post>(post); var dbPost = _postRepository.FindById(post.Id); dbPost.Message = postModel.Message; _postRepository.Update(dbPost); return Ok(); }