예제 #1
0
 public override void UpdateUser(User user)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var uDS = new UserDataStore(transaction);
         uDS.Update(user);
         transaction.Commit();
     }
 }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            try
            {
                using (var transaction = new TransactionScope(_mConfiguration))
                {
                    if (deleteAllRelatedData)
                    {
                        var  dataStore                 = new UserDataStore(transaction);
                        User user                      = dataStore.FindByName(ApplicationName, username);
                        var  userInRoleStore           = new UserInRoleDataStore(transaction);
                        IList <UserInRole> userInRoles = userInRoleStore.FindForUser(ApplicationName, user);
                        foreach (UserInRole ur in userInRoles)
                        {
                            ur.Deleted = true;
                            userInRoleStore.Update(ur);
                        }
                    }

                    var  dataStore1 = new UserDataStore(transaction);
                    User user1      = dataStore1.FindByName(ApplicationName, username);
                    if (user1 == null)
                    {
                        throw new UserNotFoundException(username);
                    }

                    // Rename the user before deleting, this will allow a new user with the same name.
                    user1.Name    = user1.Name + DateTimeHelper.GetCurrentTimestamp();
                    user1.Deleted = true;
                    dataStore1.Update(user1);

                    transaction.Commit();
                }

                return(true);
            }
            catch (UserNotDeletedException ex)
            {
                LogException(ex, "DeleteUser");
                return(false);
            }
        }