public async Task <IActionResult> Register([FromBody] RegisterPayload registerPayload) { try { var existingUserWithMail = _db.Users .Any(u => u.Email == registerPayload.Email); if (existingUserWithMail) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { var userToCreate = new User { Email = registerPayload.Email, FirstName = registerPayload.FirstName, LastName = registerPayload.LastName, PasswordHash = BC.HashPassword(registerPayload.Password), Role = "SimpleUser", }; _db.Users.Add(userToCreate); _db.SaveChanges(); return(Ok(new { status = true, user = userToCreate })); } } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public ActionResult <User> Create([FromBody] UserPayload payload) { try { var userToAdd = new User { FirstName = payload.FirstName, LastName = payload.LastName, Email = payload.Email, Gender = payload.Gender }; _db.Users.Add(userToAdd); _db.SaveChanges(); return(Ok(userToAdd)); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }