示例#1
0
        private static void PopulateItems(IMapper mapper, DotaAppContext context)
        {
            string lines       = File.ReadAllText(@"C:\Users\vango\source\repos\DotaApp\Sandbox\items.json");
            var    parsedItems = JsonConvert.DeserializeObject <Dictionary <string, ItemDto> >(lines);

            var items = new List <Item>();

            foreach (KeyValuePair <string, ItemDto> entry in parsedItems)
            {
                var item = mapper.Map <Item>(entry.Value);

                var itemAttributes = new List <ItemAttribute>();

                foreach (var attribute in entry.Value.ItemAttributes)
                {
                    var itemAttribute = new ItemAttribute
                    {
                        Footer = attribute.Footer,
                        Header = attribute.Header,
                        Key    = attribute.Key
                    };

                    var valueType = attribute.Value != null?attribute.Value.GetType().ToString() : typeof(string).ToString();

                    if (valueType == typeof(string).FullName)
                    {
                        itemAttribute.Value = attribute.Value;
                    }
                    else
                    {
                        itemAttribute.Value = string.Join(";", attribute.Value);
                    }

                    itemAttributes.Add(itemAttribute);
                }

                item.ItemAttributes = itemAttributes;
                items.Add(item);
            }

            context.Items.AddRange(items);
            context.SaveChanges();
        }
示例#2
0
        private static async Task PopulateTeams(IMapper mapper, DotaAppContext context, HttpClient client)
        {
            var response = await client.GetAsync(TEAMS_URL);

            var content = await response.Content.ReadAsStringAsync();

            var teamDtos = JsonConvert.DeserializeObject <List <TeamDto> >(content);
            var teams    = new List <Team>();

            foreach (var teamDto in teamDtos)
            {
                var team = mapper.Map <Team>(teamDto);

                teams.Add(team);
            }

            context.Teams.AddRange(teams);
            context.SaveChanges();
        }
示例#3
0
        private static async Task PopulateHeroesAndRoles(IMapper mapper, DotaAppContext context, HttpClient client)
        {
            var response = await client.GetAsync(HERO_STATS_URL);

            var content = await response.Content.ReadAsStringAsync();

            var heroDtos = JsonConvert.DeserializeObject <List <HeroDto> >(content);
            var heroes   = new List <Hero>();

            foreach (var heroDto in heroDtos)
            {
                var hero = mapper.Map <Hero>(heroDto);

                foreach (var roleDefinition in heroDto.Roles)
                {
                    var role = context.Roles.FirstOrDefault(r => r.Name == roleDefinition);

                    if (role == null)
                    {
                        context.Roles.Add(new Role {
                            Name = roleDefinition
                        });
                        context.SaveChanges();

                        role = context.Roles.FirstOrDefault(r => r.Name == roleDefinition);
                    }

                    hero.Roles.Add(new HeroRole {
                        Role = role
                    });
                    heroes.Add(hero);
                }
            }

            context.AddRange(heroes);
            context.SaveChanges();
        }
示例#4
0
 public CommentService(DotaAppContext context)
 {
     this.context = context;
 }
示例#5
0
 private void SeedItems(DotaAppContext context)
 {
     context.Items.AddRange(this.GetDummyItems());
     context.SaveChanges();
 }
示例#6
0
 private void SeedComments(DotaAppContext context)
 {
     context.Comments.AddRange(this.GetDummyComments());
     context.SaveChanges();
 }
示例#7
0
 private void SeedHeroes(DotaAppContext context)
 {
     context.Heroes.AddRange(this.GetDummyHeroes());
     context.SaveChanges();
 }
示例#8
0
        private static void PopulateHeroAbilities(IMapper mapper, DotaAppContext context)
        {
            string lines           = File.ReadAllText(@"C:\Users\vango\source\repos\DotaApp\Sandbox\abilities.json");
            var    parsedAbilities = JsonConvert.DeserializeObject <Dictionary <string, AbilityDto> >(lines);

            var abilities = new List <Ability>();

            var filteredAbilities = parsedAbilities.Where(a => !string.IsNullOrEmpty(a.Value.AbilityName));

            foreach (KeyValuePair <string, AbilityDto> entry in filteredAbilities)
            {
                var heroName = entry.Key.Split("_")?[0];

                var hero = context.Heroes.FirstOrDefault(h => h.Name.ToLower().Replace("-", "").StartsWith(heroName.ToLower()));

                if (hero != null)
                {
                    var ability = mapper.Map <Ability>(entry.Value);

                    ability.HeroId = hero.Id;
                    ability.Hero   = hero;

                    var behaviourType = entry.Value.Behavior != null?entry.Value.Behavior.GetType().ToString() : typeof(string).ToString();

                    var manaCostType = entry.Value.ManaCost != null?entry.Value.ManaCost.GetType().ToString() : typeof(string).ToString();

                    var cooldownType = entry.Value.Cooldown != null?entry.Value.Cooldown.GetType().ToString() : typeof(string).ToString();

                    if (behaviourType == typeof(string).FullName)
                    {
                        ability.Behavior = entry.Value.Behavior;
                    }
                    else
                    {
                        ability.Behavior = string.Join(";", entry.Value.Behavior);
                    }

                    if (manaCostType == typeof(string).FullName)
                    {
                        ability.ManaCost = entry.Value.ManaCost;
                    }
                    else
                    {
                        ability.ManaCost = string.Join(";", entry.Value.ManaCost);
                    }

                    if (cooldownType == typeof(string).FullName)
                    {
                        ability.Cooldown = entry.Value.Cooldown;
                    }
                    else
                    {
                        ability.Cooldown = string.Join(";", entry.Value.Cooldown);
                    }

                    if (cooldownType == typeof(string).FullName)
                    {
                        ability.Cooldown = entry.Value.Cooldown;
                    }
                    else
                    {
                        ability.Cooldown = string.Join(";", entry.Value.Cooldown);
                    }

                    var abilityAttributes = new List <AbilityAttribute>();

                    foreach (var attribute in entry.Value.AbilityAttributes)
                    {
                        var attributeDto = new AbilityAttribute
                        {
                            Key       = attribute.Key,
                            Generated = attribute.Generated,
                            Header    = attribute.Header
                        };

                        var valueType = attribute.Value != null?attribute.Value.GetType().ToString() : typeof(string).ToString();

                        if (valueType == typeof(string).FullName)
                        {
                            attributeDto.Value = attribute.Value;
                        }
                        else
                        {
                            attributeDto.Value = string.Join(";", attribute.Value);
                        }

                        abilityAttributes.Add(attributeDto);
                    }
                    ability.AbilityAttributes = abilityAttributes;
                    abilities.Add(ability);
                }
            }

            context.Abilities.AddRange(abilities);
            context.SaveChanges();
        }
示例#9
0
 public AdminService(DotaAppContext context)
 {
     this.context = context;
 }
示例#10
0
 public TeamService(DotaAppContext context)
 {
     this.context = context;
 }
示例#11
0
 public UserService(DotaAppContext context, IOptions <AppSettings> appSettings)
 {
     this.context     = context;
     this.appSettings = appSettings.Value;
 }
示例#12
0
 private void SeedRoles(DotaAppContext context)
 {
     context.IdentityRoles.AddRange(this.GetDummyUsersRoles());
     context.SaveChanges();
 }
示例#13
0
 private void SeedUsers(DotaAppContext context)
 {
     context.Users.AddRange(this.GetDummyUsers());
     context.SaveChanges();
 }
示例#14
0
 private void SeedTeams(DotaAppContext context, List <Team> teams)
 {
     context.Teams.AddRange(teams);
     context.SaveChanges();
 }
示例#15
0
 public HeroService(DotaAppContext context)
 {
     this.context = context;
 }