public async Task <IActionResult> PutUser(int id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Account> > PostAccount(Account account) { var user = await _context.Users.FindAsync(account.UserId); if (user == null) { return(NotFound()); } account.UserName = user.Name; _context.Accounts.Add(account); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAccount", new { id = account.Id }, account)); }