public Task RemoveLoginAsync(CustomUser user, UserLoginInfo login) { var toBeRemoved = new List <IdentityUserLogin>(); foreach (var item in user.Logins) { if (login.ProviderKey == item.ProviderKey && login.LoginProvider == item.LoginProvider) { toBeRemoved.Add(item); } } foreach (var item in toBeRemoved) { user.Logins.Remove(item); } var record = new UserLogingInfoToUserIdRecord() { Key = GetLoginId(login), Id = user.Id }; this.UserLoginInfoToIdDb.Delete(record); return(Task.FromResult(true)); }
public Task AddLoginAsync(CustomUser user, UserLoginInfo login) { if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("user"); } if (!user.Logins.Any(x => x.LoginProvider == login.LoginProvider && x.ProviderKey == login.ProviderKey)) { IdentityUserLogin iul = new IdentityUserLogin { LoginProvider = login.LoginProvider, ProviderKey = login.ProviderKey }; user.Logins.Add(iul); var record = new UserLogingInfoToUserIdRecord() { Key = GetLoginId(login), Id = user.Id }; this.UserLoginInfoToIdDb.Add(record); return(UpdateAsync(user)); } return(Task.FromResult(true)); }
public Task DeleteAsync(CustomUser user) { foreach (var item in user.Logins) { var record = new UserLogingInfoToUserIdRecord() { Key = GetLoginId(new UserLoginInfo(item.LoginProvider, item.LoginProvider)), Id = user.Id }; this.UserLoginInfoToIdDb.Delete(record); } return(Task.FromResult(this.UserDb.Delete(user))); }