Beispiel #1
0
        public bool Execute(TaskAbstract taskAbstract)
        {
            var task       = (ForceAccountRefreshTask)taskAbstract;
            var itemId     = task.ItemID;
            var account    = _accountService.Get(task.AccountID);
            var accountant = _accountService.GetAccountantsFromAccount(account);
            var isEmailNotificationRequired = account != null && account.CobrandToUse != null && account.CobrandToUse.CobrandSettings != null
                ? account.CobrandToUse.CobrandSettings.EnableEmailNotification
                : false;
            var forceRefreshRunner = ObjectFactory.GetInstance <ForceRefreshFacade>();
            var reportProgress     = _taskService.GetTaskProgressReporter(task.ID);

            var context = RequestContext.Current;

            var numWealthItemsProcessed = 0;
            var result = forceRefreshRunner.ForceRefreshAccount(context, account, itemId, out numWealthItemsProcessed, reportProgress);

            if (result && numWealthItemsProcessed > 0 && task.ShouldSendUpdateNotification)
            {
                // Send email informing user that their financial accounts have updated
                ApplicationNotification.SendEmailForFinancialAccountsUpdated(MessageType.Email, account, numWealthItemsProcessed);
            }
            else
            {
                SendBankAccountFailureEmailNotification(account, accountant, isEmailNotificationRequired);
            }
            return(false);
        }
Beispiel #2
0
        public bool Execute(TaskAbstract taskAbstract)
        {
            var task       = taskAbstract as LinkAccountsTask;
            var itemIds    = task.ItemIds;
            var account    = _accountService.Get(task.AccountID);
            var accountant = _accountService.GetAccountantsFromAccount(account);
            var isEmailNotificationRequired = account != null && account.CobrandToUse != null && account.CobrandToUse.CobrandSettings != null
                ? account.CobrandToUse.CobrandSettings.EnableEmailNotification
                : false;
            var context                 = task.Context as RequestContext;
            var taskID                  = task.ID;
            var wealthService           = ObjectFactory.GetInstance <IWealthService>();
            var reportProgress          = _taskService.GetTaskProgressReporter(taskID);
            var sendNotificationEmail   = Convert.ToBoolean(ConfigurationManager.AppSettings["SendFinancialAccountAddedEmail"]);
            int?wealthItemReplacementId = null;

            if (task.WealthItemReplacementIds != null)
            {
                wealthItemReplacementId = task.WealthItemReplacementIds.FirstOrDefault();
            }

            var success = _yodleeService.AddYodleeAccounts(itemIds, account, context, reportProgress, sendNotificationEmail, wealthItemIdToReplace: wealthItemReplacementId);

            if (success)
            {
                if (wealthItemReplacementId.HasValue)
                {
                    var wealthItemToReplace = wealthService.GetWealthItem(wealthItemReplacementId.Value);
                    if (wealthItemToReplace == null)
                    {
                        throw new Exception(string.Format("WealthItemToReplaceId is null for linkaccounttask. WealthitemToReplaceid:{0} ", wealthItemReplacementId.Value));
                    }

                    var owner = wealthItemToReplace.Owners.Select(x => x.Entity).FirstOrDefault();

                    wealthService.UpdateCategories(owner, task.WealthItemCategoryAssociations);
                    wealthService.DeleteWealthItem(wealthItemToReplace);
                }
                else
                {
                    wealthService.UpdateCategories(account.GetEntity(), task.WealthItemCategoryAssociations);
                }

                _pendingActionsService.AddAccountsLinked(account.ID, task.ID);
                _scoreService.CalculateScoreAsync(account);
                _taskService.UpdateTaskStatusText(task.ID, "Accounts successfully added.");
            }
            else
            {
                _pendingActionsService.AddGenericMessagePA(account.ID, "Financial Accounts Linking",
                                                           "We've encountered an error trying to link your financial accounts. Please try again later. We apologise for the inconvenience.",
                                                           new[] { FuncArea.WEALTH }, task.ID);

                var adminMessage = string.Format("LinkAccounts Task failed. TaskID: {0}. AccountID: {1} Email:{2}",
                                                 task.ID, account.ID, account.EmailAddress);
                _taskService.UpdateTaskStatusText(task.ID, MPRWealth.YodleeAccountRefreshFailure);
                _batchTasksNotifier.NotifyAdmins(adminMessage, string.Format("BatchTask ERROR. LinkAccountsTask{0} failed", task.ID));
                SendBankAccountFailureEmailNotification(account, accountant, isEmailNotificationRequired);
            }

            return(success);
        }