public async Task <ActionResult> RegisterAsync([FromBody] RegisterValidationModel model) { if (!ModelState.IsValid) { return(BadRequest()); } if (!await _storage.TryAddUserAsync(model)) { return(Conflict()); } return(Ok()); }
public async Task <bool> TryAddUserAsync(RegisterValidationModel model) { return(await Task.Run(async() => { if (model == null) { throw new ArgumentNullException(nameof(model)); } var user = new User(model.Login, model.Password); if (await _dbContext.Users.FirstOrDefaultAsync(u => u.Login == user.Login) is { }) { return false; } _dbContext.Users.Add(user); await _dbContext.SaveChangesAsync(); return true; }));
public IActionResult Register([FromBody] RegisterValidationModel model) { throw new NotImplementedException(); }