public async Task <IActionResult> PutEmployees([FromRoute] int id, [FromBody] Employees employees) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employees.Id) { return(BadRequest()); } _context.Entry(employees).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Account> > AddAccountAsync([FromBody] Account account) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await db.accounts.AddAsync(account); await db.SaveChangesAsync(); return(Created("Account Created", account)); }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }