public async Task <Gambler> Create(AddGamblerViewModel model) { var gambler = await _dbContext.Gamblers.FirstOrDefaultAsync(g => g.UserName.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase) && g.DisplayName.Equals(model.DisplayName, StringComparison.InvariantCultureIgnoreCase)); if (gambler == null) { var passwordHasher = new PasswordHasher <Gambler>(); gambler = new Gambler { UserName = model.Name, DisplayName = model.DisplayName }; gambler.Password = passwordHasher.HashPassword(gambler, model.Password); await _dbContext.Gamblers.AddAsync(gambler); await _dbContext.SaveChangesAsync(); } return(gambler); }
public async Task <IActionResult> Post([FromBody] AddGamblerViewModel model) { var gambler = await _gamblerService.Create(model); return(Json(gambler.Id)); }