예제 #1
0
        public async Task<IHttpActionResult> Post(Post post)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _repository.Insert(post);
            await _repository.Save();

            return Ok(post);
        }
예제 #2
0
        public async Task<IHttpActionResult> Put(int id, Post post)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != post.Id)
            {
                return BadRequest();
            }

            _repository.Update(post);
            await _repository.Save();
            return Ok(post);
        }