Exemple #1
0
        public ContentResult AddPost(Posts post)
        {
            string json;

            ModelState.Clear();

            if (TryValidateModel(post))
            {
                var id = _blogRepository.CreatePost(post);

                json = JsonConvert.SerializeObject(new
                {
                    id      = id,
                    success = true,
                    message = "Post added successfully."
                });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id      = 0,
                    success = false,
                    message = "Failed to add the post."
                });
            }

            return(Content(json, "application/json"));
        }