public static PostLikeViewModel Create(PostLike postLike) { return new PostLikeViewModel() { PostId = postLike.PostId, User = UserViewModelMinified.Create(postLike.User) }; }
public IHttpActionResult LikePost(int postId) { var currentUserId = this.UserIdProvider.GetUserId(); var currentUser = this.Data.Users.Find(currentUserId); var post = this.Data.Posts.Find(postId); if (post == null) { return this.NotFound(); } if (this.HasAuthorization(currentUser, post)) { return this.BadRequest("Unable to like that post. You can like posts of your friends or on their wall."); } if (post.Likes.Any(p => p.UserId == currentUserId)) { return this.BadRequest("You have already like this post."); } PostLike postLike = new PostLike { PostId = post.Id, UserId = currentUserId }; this.Data.PostLikes.Add(postLike); this.Data.SaveChanges(); return this.Ok(); }