Example #1
0
        public async Task <ActionResult> AddPost([FromBody] Post post)
        {
            Console.WriteLine(post);
            Dictionary <string, string> errors = new Dictionary <string, string>();

            if (post.Title.Length < 3)
            {
                errors.Add("title", "Your title must be at least 3 characters long.");
            }
            if (post.Contents.Length < 20)
            {
                errors.Add("contents", "Your contents must be at least 20 characters long.");
            }
            if (errors.Count > 0)
            {
                return(BadRequest(new { error = errors }));
            }
            var response = await _postRepository.AddPostAsync(post.Title, post.Contents, post.Author, post.Preview);


            //return result.User != null ? Ok(new UserResponse(result.User)) : Ok(result);
            return(response.Post != null?Ok(new PostResponse(response.Post)) : Ok(response));
        }