public async Task <Guid> CreateNewTournament(NewTournamentRequest newTournamentRequest)
        {
            var newTournament = new Tournament
            {
                Id   = Guid.NewGuid(),
                Name = newTournamentRequest.Name
            };

            await _isolaniDbContext.Tournaments.AddAsync(newTournament);

            await _isolaniDbContext.SaveChangesAsync();

            return(newTournament.Id);
        }
Example #2
0
        public async Task <Guid> CreateNewChessClub(NewChessClubRequest newChessClubRequest)
        {
            var newChessClub = new ChessClub
            {
                Id   = Guid.NewGuid(),
                Name = newChessClubRequest.Name
            };

            await _isolaniDbContext.ChessClubs.AddAsync(newChessClub);

            await _isolaniDbContext.SaveChangesAsync();

            return(newChessClub.Id);
        }
        public async Task <SecurityToken> GetTokenAsync(TokenRequest tokenRequest)
        {
            var user = await _isolaniDbContext.Users.SingleOrDefaultAsync(usr => usr.Email.Equals(tokenRequest.Email));

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            VerifyPassword(user.Password, tokenRequest.Password);

            var now = DateTime.UtcNow;

            user.LastLoginDateUtc = now;

            await _isolaniDbContext.SaveChangesAsync();

            return(CreateSecurityToken(user, now));
        }
        public async Task <Guid> CreateNewUserPlayerAsync(NewUserPlayerRequest newUserPlayerRequest)
        {
            var userWithEmailExists = await
                                      _isolaniDbContext.Users
                                      .AnyAsync(user =>
                                                user.Email.Equals(newUserPlayerRequest.Email, StringComparison.OrdinalIgnoreCase));

            if (userWithEmailExists)
            {
                throw new UserExistsException();
            }

            var now = DateTime.UtcNow;

            var savedPasswordHash = AuthenticationService.CreateSaltyPasswordHash(newUserPlayerRequest.Password);

            var userId = Guid.NewGuid();

            var newUser = _objectMapper.Map <User>(newUserPlayerRequest);

            newUser.Id             = userId;
            newUser.CreatedDateUtc = newUser.LastLoginDateUtc = now;
            newUser.Password       = savedPasswordHash;

            await _isolaniDbContext.AddAsync(newUser);

            var newPlayer = _objectMapper.Map <Player>(newUserPlayerRequest);

            newPlayer.Id = userId;

            await _isolaniDbContext.AddAsync(newPlayer);

            await _isolaniDbContext.SaveChangesAsync();

            return(newUser.Id);
        }