public IActionResult Create() { var viewModel = new CreatePlayerInputModel { Races = this.racesService.GetAllRacesAsKeyValuePairs(), }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(CreatePlayerInputModel input) { if (!this.ModelState.IsValid) { return(this.Redirect("Error")); } var applicationUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.playersService.CreatePlayerAsync(input, applicationUserId); return(this.Redirect("/")); }
// TODO: Add constants for the magic numbers below. public async Task CreatePlayerAsync(CreatePlayerInputModel input, string applicationUserId) { if (this.IsPlayerCreated(applicationUserId)) { throw new InvalidOperationException("Only one player per account is allowed!"); } var player = new Player { PlayerName = input.PlayerName, Experience = 0, Money = 50_000, CreatedOn = DateTime.UtcNow, RaceId = input.RaceId, ApplicationUserId = applicationUserId, IsDeleted = false, RankId = "c907502b-94f7-403f-903b-a3f345561b9c", }; await this.playerRepository.AddAsync(player); await this.playerRepository.SaveChangesAsync(); }