Example #1
0
 public void SaveUserLogins(int memberId, IEnumerable <UserLoginInfo> logins)
 {
     using (var dbContext = new ExternalLoginsContext())
     {
         using (var dbTransaction = dbContext.Database.BeginTransaction())
         {
             try
             {
                 dbContext.Database.ExecuteSqlCommand("DELETE FROM ExternalLogins WHERE UserId=@userId", new SqlParameter("@userId", memberId));
                 foreach (var login in logins)
                 {
                     dbContext.ExternalLogins.Add(new Models.ExternalLogin()
                     {
                         LoginProvider = login.LoginProvider,
                         ProviderKey   = login.ProviderKey,
                         UserId        = memberId
                     });
                 }
                 dbContext.SaveChanges();
                 dbTransaction.Commit();
             }
             catch (Exception)
             {
                 dbTransaction.Rollback();
                 throw;
             }
         }
     }
 }
Example #2
0
        public IEnumerable <int> Find(UserLoginInfo login)
        {
            IEnumerable <int> userId;

            using (var dbContext = new ExternalLoginsContext())
            {
                userId = dbContext.ExternalLogins
                         .Where(e => e.LoginProvider == login.LoginProvider &&
                                e.ProviderKey == login.ProviderKey)
                         .Select(e => e.UserId).ToList();
            }
            return(userId);
        }
Example #3
0
        public IEnumerable <IdentityMemberLogin <int> > GetAll(int userId)
        {
            IEnumerable <IdentityMemberLogin <int> > users;

            using (var dbContext = new ExternalLoginsContext())
            {
                users = dbContext.ExternalLogins
                        .Where(e => e.UserId == userId)
                        .Select(e => new IdentityMemberLogin <int>
                {
                    LoginProvider = e.LoginProvider,
                    ProviderKey   = e.ProviderKey,
                    UserId        = e.UserId
                }).ToList();
            }
            return(users.ToList());
        }
Example #4
0
 public void DeleteUserLogins(int memberId)
 {
     using (var dbContext = new ExternalLoginsContext())
     {
         using (var dbTransaction = dbContext.Database.BeginTransaction())
         {
             try
             {
                 dbContext.Database.ExecuteSqlCommand("DELETE FROM ExternalLogins WHERE UserId=@userId", new SqlParameter("@userId", memberId));
                 dbContext.SaveChanges();
                 dbTransaction.Commit();
             }
             catch (Exception)
             {
                 dbTransaction.Rollback();
             }
         }
     }
 }