private async Task UpdateUser(Guid userProfileId, Shared.Enums.BattleNetRegion region) { using (var scope = this.provider.CreateScope()) { var alexandriaContext = scope.ServiceProvider.GetService <Alexandria.EF.Context.AlexandriaContext>(); var heroesOfTheStormContext = scope.ServiceProvider.GetService <HeroesOfTheStormContext>(); var user = await alexandriaContext.UserProfiles.Include(u => u.ExternalAccounts).FirstOrDefaultAsync(u => u.Id == userProfileId); if (user == null) { return; } var battleNet = user.ExternalAccounts.FirstOrDefault(e => e.Provider == Shared.Enums.ExternalProvider.BattleNet); if (battleNet == null) { return; } var result = await this.hotslogsClient.GetPlayerRankings(battleNet.Name, (int)region); var rankings = result.Select((r) => AutoMapper.Mapper.Map <EF.Models.ExternalRanking>(r, opts => { opts.Items["UserProfileId"] = userProfileId; opts.Items["Region"] = region; })).ToList(); heroesOfTheStormContext.ExternalRankings.AddRange(rankings); await heroesOfTheStormContext.SaveChangesAsync(); } }
public HOTSLogsUpdate(Guid userId, Shared.Enums.BattleNetRegion region = Shared.Enums.BattleNetRegion.NorthAmerica) { this.UserProfileId = userId; this.Region = region; }