Example #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();
            }
        }
Example #2
0
 partial void DeleteNetworkUser(NetworkUser instance);
Example #3
0
 partial void UpdateNetworkUser(NetworkUser instance);
Example #4
0
 partial void InsertNetworkUser(NetworkUser instance);
Example #5
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;
            }
        }