예제 #1
0
        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();
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
                }
            }
        }