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(); }
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(); }
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(); }
private void SeedItems(DotaAppContext context) { context.Items.AddRange(this.GetDummyItems()); context.SaveChanges(); }
private void SeedComments(DotaAppContext context) { context.Comments.AddRange(this.GetDummyComments()); context.SaveChanges(); }
private void SeedHeroes(DotaAppContext context) { context.Heroes.AddRange(this.GetDummyHeroes()); context.SaveChanges(); }
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(); }
private void SeedRoles(DotaAppContext context) { context.IdentityRoles.AddRange(this.GetDummyUsersRoles()); context.SaveChanges(); }
private void SeedUsers(DotaAppContext context) { context.Users.AddRange(this.GetDummyUsers()); context.SaveChanges(); }
private void SeedTeams(DotaAppContext context, List <Team> teams) { context.Teams.AddRange(teams); context.SaveChanges(); }