Example #1
0
        public ActionResult CloseAccount(CloseAccountViewModel closeAccountData)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            string userEmail = User.Identity.Name;

            _bankManageService.CloseAccount(userEmail, closeAccountData.Password, closeAccountData.AccountNumber);
            return(this.RedirectToAction("ShowAccounts"));
        }
Example #2
0
        public ActionResult CloseAccount(int?id)
        {
            Account account = db.Accounts.Find(id);

            // Incomes and Expenses Associated with this account no longer have an associated account.
            // The returned View will list these so they can be reassigned to a new Account
            CloseAccountViewModel closeAccountVM = new CloseAccountViewModel();

            closeAccountVM.IncomesWithNoAssociatedAccount  = account.Incomes.ToList();
            closeAccountVM.ExpensesWithNoAssociatedAccount = account.Expenses.ToList();

            // The VM needs to know what Account was closed as well as a list of all Active Accounts to choose from
            // in the next view when reassigning the Incomes and Expenses.
            closeAccountVM.ClosedAccount     = account;
            closeAccountVM.AllActiveAccounts = db.Accounts.Where(a => a.IsActive == true).ToList();

            // Set the associated Expenses' and Incomes' AccountId's to 0
            foreach (var inc in account.Incomes)
            {
                inc.AccountId = 0;
            }
            foreach (var exp in account.Expenses)
            {
                exp.AccountId = 0;
            }

            // Get the Account's closing Balance
            decimal balance = 0;

            foreach (var tx in db.Transactions.Where(t => t.AccountId == id))
            {
                if (tx.IsCredit)
                {
                    balance += tx.Amount;
                }
                else
                {
                    balance -= tx.Amount;
                }
            }
            account.ClosingBalance = balance;
            account.IsActive       = false;
            account.Closed         = DateTime.UtcNow;

            // Set the Account's
            account.CategoryId = db.AccountCategories.First(ac => ac.Category == "Closed").Id;

            db.Entry(account).State = EntityState.Modified;
            db.SaveChanges();

            return(View(closeAccountVM));
        }
        public IActionResult CloseAccountPost(CloseAccountViewModel viewModel)
        {
            // Admin impersonating a user shouldn't be able to close the user's account
            if (LoginHelper.IsUserBeingImpersonated(User))
            {
                return(RedirectToAction("ManageAccountGet", "ManageAccount"));
            }

            viewModel.ParseAndValidateParameters(Request, m => m.Password);

            if (viewModel.HasAnyErrors())
            {
                return(View("CloseAccount", viewModel));
            }

            // Get the current user
            User currentUser = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository);

            // Check password
            bool isValidPassword = userRepository.CheckPassword(currentUser, viewModel.Password);

            if (!isValidPassword)
            {
                viewModel.AddErrorFor(m => m.Password, "Could not verify your password");
                return(View("CloseAccount", viewModel));
            }

            // Collect list of organisations associated with the user
            List <Organisation> possiblyOrphanedOrganisations = currentUser.UserOrganisations
                                                                .Select(uo => uo.Organisation)
                                                                .Distinct()
                                                                .ToList();

            RetireUserAccount(currentUser);

            SendAccountClosedEmail(currentUser);

            // Collect list of orphaned organisations after the user has been retired
            List <Organisation> orphanedOrganisations = possiblyOrphanedOrganisations.FindAll(org => org.GetIsOrphan());

            InformGeoOfOrphanedOrganisations(orphanedOrganisations);

            // Log user out and redirect to success page
            IActionResult accountClosedSuccess = RedirectToAction("CloseAccountComplete", "CloseAccount");

            return(LoginHelper.Logout(HttpContext, accountClosedSuccess));
        }
        public IActionResult CloseAccountGet()
        {
            // Admin impersonating a user shouldn't be able to close the user's account
            if (LoginHelper.IsUserBeingImpersonated(User))
            {
                return(RedirectToAction("ManageAccountGet", "ManageAccount"));
            }

            // Get the current user
            User currentUser = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository);

            var viewModel = new CloseAccountViewModel
            {
                IsSoleUserRegisteredToAnOrganisation = currentUser.IsSoleUserOfOneOrMoreOrganisations()
            };

            // Return the Change Personal Details form
            return(View("CloseAccount", viewModel));
        }
Example #5
0
        public async Task <IActionResult> CloseAccount([FromForm] CloseAccountViewModel formData)
        {
            var checkResult = await CheckUserRegisteredOkAsync();

            if (checkResult != null)
            {
                return(checkResult);
            }

            // prevent impersonation
            if (IsImpersonatingUser)
            {
                RedirectToAction <AccountController>(nameof(AccountController.ManageAccount));
            }

            // return to page if there are errors
            if (ModelState.IsValid == false)
            {
                return(View(nameof(CloseAccount), formData));
            }

            // execute change password process
            var errors = await CloseAccountService.CloseAccountAsync(VirtualUser, formData.EnterPassword, VirtualUser);

            if (errors.ErrorCount > 0)
            {
                ModelState.Merge(errors);
                return(View(nameof(CloseAccount), formData));
            }

            // force sign-out then redirect to completed page
            var redirectUrl = Url.Action <CloseAccountController>(nameof(CloseAccountCompleted));

            // logout the
            return(await LogoutUser(redirectUrl));
        }