private async Task<List<UserRationModel>> GetFriendScore(UserDto user) { List<UserRationModel> model = null; var externalUserId = user.Logins.First(i => i.LoginType == ExternalLoginType.Google).ExternalUserId; var token = _tokenRepository.Get(externalUserId); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://www.googleapis.com/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{token}"); // New code: var response = await client.GetAsync($"plus/v1/people/{externalUserId}/people/visible"); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); var parsedUserIds = ParseIds(responseJson); model = await GetUserFriendsScores(parsedUserIds); } } return model; }
public void UpdateExternalLoginValues(UserDto userDto, string firstName, string lastName, string photoRec) { using (var context = new PicturesDbContext()) { var userEntity = new User {Id = userDto.Id}; var entity = context.Users.Attach(userEntity); var wasModified = false; if (userDto.PhotoRec != photoRec) { entity.PhotoRec = photoRec; //context.Entry(entity).Property((item) => item.PhotoRec).IsModified = true; wasModified = true; } if (userDto.FirstName != firstName) { entity.FirstName = photoRec; //context.Entry(entity).Property((item) => item.FirstName).IsModified = true; wasModified = true; } if (userDto.LastName != lastName) { entity.LastName = lastName; //context.Entry(entity).Property((item) => item.LastName).IsModified = true; } if (wasModified) context.SaveChanges(); } }