コード例 #1
0
        public IResult DeleteAccount(User user)
        {
            var users = new List <User> {
                user
            };

            _deleteAccountService._targetUsers = users;

            var userId = _updatePermissionService.SysIdFinder(user);

            for (int i = 0; i < 3; i++)
            {
                Permission perms = new Permission(userId);
                foreach (string s in Enum.GetValues(typeof(AuthZEnum)))
                {
                    perms.RemovePermission(s);
                }
                try
                {
                    _updatePermissionService._permissions = new List <Permission> {
                        perms
                    };
                    var permResult = _updatePermissionService.Update();
                    if (permResult.IsSuccess)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    ErrorController handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Permissions failed to delete");
                }
            }
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var deleteResult = _deleteAccountService.Delete();
                    if (deleteResult.IsSuccess)
                    {
                        LogService.Log(deleteResult.Message);
                        return(deleteResult);
                    }
                }
                catch (Exception e)
                {
                    ErrorController handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Failed to delete Account");
                }
            }
            return(new CheckResult("Failed to Delete Account", false));
        }
コード例 #2
0
        public IResult CreateAccount(Account account, User user)
        {
            var users = new List <User> {
                user
            };
            var accounts = new List <Account> {
                account
            };

            _createAccountService._newAccounts = accounts;
            _updateAccountService._newUsers    = users;
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var createAccountResult = _createAccountService.Create();
                    if (createAccountResult.IsSuccess)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    ErrorController handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Failed to create Account");
                }
            }
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var updateAccountResult = _updateAccountService.Update();
                    if (updateAccountResult.IsSuccess)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    ErrorController handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Failed to create Account");
                }
            }
            var        id    = _updatePermissionService.SysIdFinder(user);
            Permission perms = new Permission(id);

            foreach (string s in Enum.GetValues(typeof(StandardUser)))
            {
                perms.AddPermission(s);
            }
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    _updatePermissionService._permissions = new List <Permission> {
                        perms
                    };
                    var permResult = _updatePermissionService.Update();
                    if (permResult.IsSuccess)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    ErrorController handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Failed to create Permissions");
                }
            }


            var checkResult = new CheckResult("Account Successfully Created", true);

            LogService.Log(checkResult.Message);
            return(checkResult);
        }