public IActionResult YourIncome(IncomeVm viewModel)
        {
            ModelState.Clear();

            var id = RouteData.Values["id"];

            if (id == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            ApplicationSessionState.CheckSessionStatus(id.ToString());
            viewModel.EnabledPartialSave = _portalSettings.Features.EnablePartialSave && LoggedInUser.IsLoggedInUser;

            Guid guid = Guid.Parse(id.ToString());

            IncomeAndExpenditure incomeAndExpenditure = ApplicationSessionState.GetIncomeAndExpenditure(guid);

            _gtmService.RaiseBudgetCalculatorHouseholdDetailsEvent(viewModel, LoggedInUserId, incomeAndExpenditure?.HousingStatus, incomeAndExpenditure?.EmploymentStatus);

            viewModel = _mapper.Map(incomeAndExpenditure, viewModel);

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Index(DataProtectionVm model)
        {
            if (!ModelState.IsValid)
            {
                // List of days, months, years will not have been posted back, therefore repopulate
                _buildDataProtectionVm.PopulateDateComponents(model);
                _gtmService.RaiseRegistrationEvent_AccountDetailsEntered(model, "Invalid account details");

                return(View(model));
            }

            var dataProtectionDto    = _mapper.Map <DataProtectionVm, DataProtectionDto>(model);
            var dataProtectionResult = await _registerService.CheckDataProtection(dataProtectionDto);

            if (!dataProtectionResult.IsSuccessful)
            {
                AddErrors(dataProtectionResult.MessageForUser);

                model.NotificationMessage = dataProtectionResult.MessageForUser;
                _gtmService.RaiseRegistrationEvent_AccountDetailsEntered(model, "Incorrect account details");
                _buildDataProtectionVm.PopulateDateComponents(model);

                return(View(model));
            }

            var webRegisteredDto      = _mapper.Map <DataProtectionVm, WebRegisteredDto>(model);
            var isWebRegisteredResult = await _registerService.CheckIsWebRegistered(webRegisteredDto);

            if (!isWebRegisteredResult.IsSuccessful)
            {
                AddErrors(isWebRegisteredResult.MessageForUser);

                model.NotificationMessage = isWebRegisteredResult.MessageForUser;
                _gtmService.RaiseRegistrationEvent_AccountDetailsEntered(model, "Already registered");
                _buildDataProtectionVm.PopulateDateComponents(model);

                return(View(model));
            }

            var registrationPending =
                await _registerService.IsPendingRegistration(model.LowellReference);

            if (registrationPending)
            {
                var error = "Account details provided is already registered. Please confirm your email account and login.";

                AddErrors(error);

                model.NotificationMessage = error;

                ModelState.AddModelError(string.Empty,
                                         "Account details provided is already registered. Please confirm your email account and login.");

                return(View(model));
            }

            ApplicationSessionState.SaveHasPassedDataProtection();

            var registerVm = new RegisterVm {
                LowellReference = model.LowellReference
            };

            _gtmService.RaiseRegistrationEvent_AccountDetailsEntered(registerVm, null);

            return(View("CompleteRegistration", registerVm));
        }
コード例 #3
0
        public async Task <IActionResult> BudgetComplete(
            [FromQuery(Name = "customerReference")]
            string base64EncodedEncryptedCustomerReference,
            [FromQuery(Name = "errorCode")] string errorCode)
        {
            if (!_portalSetting.Features.EnableOpenWrks)
            {
                return(NotFound());
            }

            var lowellSurrogateKey = ApplicationSessionState.GetTopLowellSurrogateKey();
            var lowellReference    = ApplicationSessionState.GetTopLowellReference();

            if (lowellSurrogateKey == null || lowellSurrogateKey == Guid.Empty)
            {
                // At this point it looks like the Users's session has expired and was forced to re-login.
                // As a result all the surrogatekeys will be empty the following lines will save surrogate key to session again
                // then we will simply get the top key.

                var accountSummaries = await _accountService.GetAccounts(GetCaseflowUserId());

                var lowellReferences = accountSummaries.Select(x => x.AccountReference).ToList();
                var surrogateKeysByLowellReference =
                    ApplicationSessionState.AddLowellReferenceSurrogateKeys(lowellReferences);
                lowellSurrogateKey = ApplicationSessionState.GetTopLowellSurrogateKey();
                lowellReference    = ApplicationSessionState.GetTopLowellReference();
            }

            var occurrenceId = Request.Headers.ContainsKey(TraceMiddleware.TraceHeaderName)
                ? Request.Headers[TraceMiddleware.TraceHeaderName].ToString()
                : "";

            var errorModel = new OpenWrksErrorVm
            {
                LowellFinancialAccountSurrogateKey = lowellSurrogateKey,
                OccurrenceId = occurrenceId
            };

            var caseflowUserId = GetCaseflowUserId();

            var decryptedCustomerReference = "";

            try
            {
                var base64DecodedEncryptedCustomerRefAsString = GetBase64DecodeString(base64EncodedEncryptedCustomerReference);

                decryptedCustomerReference =
                    _cryptoAlgorithm.DecryptUsingAes(base64DecodedEncryptedCustomerRefAsString);
            }
            catch (Exception e)
            {
                Logger.LogError(e,
                                $"Unable to decode and decrypt the customerReference provided by OpenWrks. customerReference - {base64EncodedEncryptedCustomerReference}.");

                await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId());

                return(View("Error", errorModel));
            }

            if (string.IsNullOrEmpty(errorCode) &&
                string.Equals(decryptedCustomerReference, caseflowUserId, StringComparison.OrdinalIgnoreCase))
            {
                if (!string.IsNullOrWhiteSpace(lowellReference))
                {
                    var model = new OpenWrksSuccessVm
                    {
                        LowellFinancialAccountSurrogateKey = lowellSurrogateKey,
                        OccurrenceId = occurrenceId
                    };
                    if (_openWrksSetting.UseLandingPage)
                    {
                        return(View("Success", model));
                    }


                    Logger.LogInformation("Fetching translated budget from API GW");
                    var customerReference = GenerateOpenWrksCustomerReference();
                    var budget            =
                        await _openWrkService.GetOpenWorksBudgetTranslatedToCaseflowBudgetModel(
                            base64EncodedEncryptedCustomerReference);

                    Logger.LogInformation("Saving budget to Distributed Cache.");
                    ApplicationSessionState.SaveIncomeAndExpenditure(
                        budget, model.LowellFinancialAccountSurrogateKey.Value);

                    try
                    {
                        Logger.LogInformation("Saving budget to Caseflow.");
                        await _budgetCalculatorService.SaveIncomeAndExpenditure(budget, lowellReference);

                        await _webActivityService.LogOpenBankingComplete(lowellReference, GetCaseflowUserId());


                        return(RedirectToAction(
                                   "BudgetSummary",
                                   "BudgetCalculator",
                                   new { id = model.LowellFinancialAccountSurrogateKey }));
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex,
                                        $"Saving OpenBanking budget to Caseflow has returned error with code - {errorCode}.");
                        await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId());

                        return(View("Error", errorModel));
                    }
                }

                Logger.LogWarning("Account reference number is not found.");
            }
            else if (!string.IsNullOrEmpty(errorCode))
            {
                Logger.LogError($"OpenBanking has returned error with code - {errorCode}.");
            }
            else
            {
                Logger.LogError(
                    $"OpenBanking has returned invalid customer reference in BudgetComplete notification. Customer Reference {base64EncodedEncryptedCustomerReference} is not matched with {GetCaseflowUserId()}");
            }

            await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId());

            return(View("Error", errorModel));
        }
        public async Task <IActionResult> Transactions(
            TransactionsVm transactionsVm,
            int pageNumber = 1)
        {
            var value = RouteData.Values["id"];

            if (value == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            Guid.TryParse(value.ToString(), out var id);

            if (!ModelState.IsValid)
            {
                return(View(transactionsVm));
            }

            string lowellReference = ApplicationSessionState.GetLowellReferenceFromSurrogate(id);

            if (string.IsNullOrEmpty(lowellReference))
            {
                throw new Exception("No lowell reference found in cache");
            }

            Account account = ApplicationSessionState.GetAccount(lowellReference);

            if (account == null)
            {
                account = await _accountsService.GetAccount(LoggedInUserId, lowellReference);

                ApplicationSessionState.SaveAccount(account, lowellReference);
            }

            List <Transaction> transactions = ApplicationSessionState.GetTransactions(lowellReference);

            if (transactions == null)
            {
                transactions = await _transactionsService.GetTransactions(account.AccountReference);

                ApplicationSessionState.SaveTransactions(transactions, lowellReference);
            }

            if (transactions == null)
            {
                transactions = new List <Transaction>();
            }

            transactionsVm.AccountName      = account.OriginalCompany;
            transactionsVm.AccountBalance   = account.OutstandingBalance;
            transactionsVm.AccountReference = account.AccountReference;

            _gtmService.RaiseTransactionsViewedEvent(transactionsVm, LoggedInUserId, "Regular Account");
            await _webActivityService.LogAllTransactionsViewed(transactionsVm.AccountReference, LoggedInUserId);

            if (transactionsVm.FilterTransactions.DateFrom != null)
            {
                transactions = transactions.Where(x => x.Date >= transactionsVm.FilterTransactions.DateFrom).ToList();
            }

            if (transactionsVm.FilterTransactions.DateTo != null)
            {
                transactions = transactions.Where(x => x.Date <= transactionsVm.FilterTransactions.DateTo).ToList();
            }

            if (!string.IsNullOrEmpty(transactionsVm.FilterTransactions.KeyWord))
            {
                transactions = transactions.Where(x => x.Description.ToLower().Contains(transactionsVm.FilterTransactions.KeyWord.ToLower())).ToList();
            }

            transactions = transactions.OrderByDescending(x => x.Date).ToList();

            if (!transactions.Any())
            {
                transactionsVm.FilterTransactions.DateMessage = "No Results Found";
            }

            transactionsVm.PagedList =
                _mapper.Map <List <Transaction>, List <TransactionVm> >(transactions).ToPagedList(pageNumber, _pageSize);

            transactionsVm.LoggedInUserID    = LoggedInUserId;
            transactionsVm.LoggedInLowellRef = ApplicationSessionState.GetLoggedInLowellRef();

            return(View(transactionsVm));
        }