//TODO BK check EmailAddress public async Task <IActionResult> PutUsers(long id, UsersDTO usersDTO) { if (id != usersDTO.Id) { return(BadRequest()); } Users users = usersDTO.FromDTO(); _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Users> > PostUsers(UsersDTO usersDTO) { Users users = usersDTO.FromDTO(); List <Users> usersList = await _context.Users.ToListAsync(); IEnumerable <Users> emailusers = usersList.Where(e => e.EmailAddress == users.EmailAddress); if (emailusers.Count() > 0) { return(BadRequest("die Emailadresse ist bereits vergeben")); } _context.Users.Add(users); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUsers", new { id = users.Id }, users)); }