Exemple #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;
             }
         }
     }
 }
Exemple #2
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();
             }
         }
     }
 }