示例#1
0
        public async Task <IActionResult> PostBlog([FromBody] Blogs blog, [FromHeader] string UserName)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            await _blogsRepository.Add(blog);

            var results = new ObjectResult(blog)
            {
                StatusCode = (int)HttpStatusCode.OK
            };

            return(results);
        }
示例#2
0
        public async Task <IActionResult> PostBlog([FromBody] Blogs blog, [FromHeader] string UserName)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Models.Users user = _bUsersRepository.GetAll().Where(P => P.UserName == UserName).FirstOrDefault();

            blog.UserId = user.UserId;
            await _blogsRepository.Add(blog);

            var results = new ObjectResult(blog)
            {
                StatusCode = (int)HttpStatusCode.OK
            };

            return(results);
        }