public string CreateUser(SocialIdentity identity) { using (var context = new SocialDataContext(this.connectionString)) { var socialUserId = Guid.NewGuid(); var networkUser = new NetworkUser { NetworkUserId = identity.Id, Provider = identity.ProviderName, SocialUserId = socialUserId, Token = identity.Token, Secret = identity.Secret, Expires = identity.Expires, Name = identity.Name }; context.NetworkUsers.InsertOnSubmit(networkUser); context.SubmitChanges(); return networkUser.Name; } }
public void AssociateIdentity(string userId, SocialIdentity identity) { using (var context = new SocialDataContext(this.connectionString)) { /// Associate the network user to the social user var networkUser = context.NetworkUsers.FirstOrDefault(u => u.NetworkUserId == identity.Id && u.Provider == identity.ProviderName); if (networkUser == null) { networkUser = new NetworkUser { NetworkUserId = identity.Id, Provider = identity.ProviderName, SocialUserId = new Guid(userId), Token = identity.Token, Secret = identity.Secret, Expires = identity.Expires, Name = identity.Name }; context.NetworkUsers.InsertOnSubmit(networkUser); } else { var oldUserID = networkUser.SocialUserId; networkUser.SocialUserId = new Guid(userId); } /// remove old network user associations within the same provider var oldNetworkUsers = context.NetworkUsers.Where(u => u.Provider == identity.ProviderName && u.NetworkUserId != identity.Id && u.SocialUserId.ToString() == userId).ToList(); context.NetworkUsers.DeleteAllOnSubmit(oldNetworkUsers); context.SubmitChanges(); } }
public IEnumerable<SocialIdentity> GetIdentities(string userId) { using (var context = new SocialDataContext(this.connectionString)) { return context.NetworkUsers.Where(u => u.SocialUserId.ToString() == userId).Select( u => new SocialIdentity { Id = u.NetworkUserId, ProviderName = u.Provider, Token = u.Token, Secret = u.Secret, Expires = u.Expires, Name = u.Name }).ToList(); } }
public string FindIdentity(SocialIdentity identity) { using (var context = new SocialDataContext(this.connectionString)) { var user = context.NetworkUsers.FirstOrDefault(u => u.NetworkUserId == identity.Id && u.Provider == identity.ProviderName); if (user != null) { user.Token = identity.Token; user.Secret = identity.Secret; user.Expires = identity.Expires; user.Name = identity.Name; context.SubmitChanges(); //return user.SocialUserId.ToString(); return user.Name; } else { return null; } } }