예제 #1
0
        public async Task <IActionResult> PutAsync(int id, CreateOrUpdateBookModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var title   = model.Title;
            var author  = model.Author;
            var year    = model.Year;
            var updated = await books.UpdateAsync(id, title, author, year);

            if (!updated)
            {
                return(StatusCode(500));
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PostAsync(CreateOrUpdateBookModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var title  = model.Title;
            var author = model.Author;
            var year   = model.Year;
            var id     = await books.AddAsync(title, author, year);

            if (id <= 0)
            {
                return(StatusCode(500));
            }

            return(CreatedAtAction("Get", new { id, title }));
        }