Exemplo n.º 1
0
        public async Task<Player> CreatePlayerForUserAsync(ApplicationUser user)
        {
            var player = new Player { User = user };

            _db.Players.Add(player);
            await _db.SaveChangesAsync();

            return player;
        }
        public async Task <Player> CreatePlayerForUserAsync(ApplicationUser user)
        {
            var player = new Player {
                User = user
            };

            _db.Players.Add(player);
            await _db.SaveChangesAsync();

            return(player);
        }
Exemplo n.º 3
0
        public async Task<Player> CreatePlayerWithTagAsync(string tag)
        {
            if (string.IsNullOrEmpty(tag))
            {
                throw new ArgumentNullException(nameof(tag));
            }

            Player player;

            // See if this player already exists
            player = await _db.Players
                .SingleOrDefaultAsync(x => tag.Equals(x.Tag, StringComparison.OrdinalIgnoreCase));
            if (player == null)
            {
                player = new Player { Tag = tag };
                _db.Add(player);
                await _db.SaveChangesAsync();
            }

            return player;
        }
        public async Task <Player> CreatePlayerWithTagAsync(string tag)
        {
            if (string.IsNullOrEmpty(tag))
            {
                throw new ArgumentNullException(nameof(tag));
            }

            Player player;

            // See if this player already exists
            player = await _db.Players
                     .SingleOrDefaultAsync(x => tag.Equals(x.Tag, StringComparison.OrdinalIgnoreCase));

            if (player == null)
            {
                player = new Player {
                    Tag = tag
                };
                _db.Add(player);
                await _db.SaveChangesAsync();
            }

            return(player);
        }
        private async Task CreatePlayerForUserAsync(ApplicationUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            // Make sure the user has a player entity
            var player = await _db.Players
                .Include(x => x.User)
                .SingleOrDefaultAsync(x => x.User.Id == user.Id);
            if (player == null)
            {
                var rating = new Rating { MatchMakingRating = 1500 };
                _db.Add(rating);

                // Setup default rank
                var rank = new Rank { Rating = rating };
                var defaultSeason = await _db.DefaultSeasons
                    .Include(x => x.Season)
                    .FirstOrDefaultAsync();
                if (defaultSeason != null)
                {
                    var season = await _db.Seasons
                        .Include(x => x.Brackets)
                        .SingleOrDefaultAsync(x => x.SeasonId == defaultSeason.Season.SeasonId);
                    if (season != null && season.Brackets.Any(x => x.Type == RankBrackets.NeverLucky))
                    {
                        rank.RankBracket = season.Brackets.Single(x => x.Type == RankBrackets.NeverLucky);
                    }
                }

                _db.Add(rank);

                player = new Player
                {
                    User = user,
                    Rank = rank
                };

                _db.Add(player);
                await _db.SaveChangesAsync();
            }
        }