Пример #1
0
        public async Task <IActionResult> Post([FromBody] User user)
        {
            try
            {
                db.Users.Add(user);
                await db.SaveChangesAsync();

                return(Created(user));
            }
            catch
            {
                db.Users.Local.Remove(user);
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] Book book)
        {
            try
            {
                db.Books.Add(book);
                await db.SaveChangesAsync();

                return(Created(book));
            }
            catch
            {
                db.Books.Local.Remove(book);
                return(BadRequest());
            }
        }