public IHttpActionResult AddCommentToPost(int postId,
            AddPostBindingModel model)
        {
            //check if the post exists
            var post = this.Context.Posts.Find(postId);
            if (post == null)
            {
                return this.NotFound();
            }

            //if the model is empty
            if (model==null)
            {
                return this.BadRequest("No values are sent!");
            }

            //check for validations
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            //if everything is OK
            var userId = this.User.Identity.GetUserId();
            var comment = new Comment()
            {
                Content = model.Content,
                PostedOn = DateTime.Now,
                AuthorId = userId
            };
            post.Comments.Add(comment);
            this.Context.SaveChanges();

            return this.Ok();
        }
        public async Task<HttpResponseMessage> AddPostToUser(AddPostBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return await this.BadRequest(this.ModelState).ExecuteAsync(new CancellationToken());
            }

            if (model == null)
            {
                return await this.BadRequest("Post cannot be empty.").ExecuteAsync(new CancellationToken());
            }

            var user = this.Data.Users.FirstOrDefault(u => u.UserName == model.username);
            if (user == null)
            {
                return await this.NotFound().ExecuteAsync(new CancellationToken());
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser = this.Data.Users.FirstOrDefault(x => x.Id == currentUserId);
            if (currentUser == null)
            {
                return await this.BadRequest("Invalid user token! Please login again!").ExecuteAsync(new CancellationToken());
            }

            if (!user.Friends.Contains(currentUser))
            {
                return await this.BadRequest("Not allowed. Wall-owner must be a friend or user.").ExecuteAsync(new CancellationToken());
            }

            var newPost = new Post()
            {
                Content = model.postContent,
                Author = currentUser,
                PostedOn = DateTime.Now
            };

            user.Posts.Add(newPost);
            this.Data.SaveChanges();

            var dbPost = this.Data.Posts.FirstOrDefault(p => p.Id == newPost.Id);
            var postReturnView = new PostViewModel()
            {
                Id = dbPost.Id,
                AuthorId = dbPost.Author.Id,
                AuthorUsername = dbPost.Author.UserName,
                AuthorProfileImage = dbPost.Author.ProfilePicture,
                WallOwnerId = user.Id,
                PostContent = dbPost.Content,
                Date = dbPost.PostedOn,
                LikesCount = dbPost.Likes.Count,
                Liked = false,
                TotalCommentsCount = 0,
                Comments = new List<CommentViewModel>()
            };

            return await this.Ok(new
            {
                message = "Post successfully added.",
                post = postReturnView
            }).ExecuteAsync(new CancellationToken());
        }