internal static void AddOrUpdateAccount(EmployerAccountReferenceData account)
        {
            if (TestEnvironment.ValidateSpecsOnly)
            {
                return;
            }

            using (var connection = new SqlConnection(TestEnvironment.Variables.DedsDatabaseConnectionString))
            {
                var rowsAffected = connection.Execute("UPDATE dbo.DasAccounts " +
                                                      "SET Balance = @Balance " +
                                                      "WHERE AccountId = @AccountId",
                                                      new
                {
                    AccountId = account.Id,
                    Balance   = account.Balance,
                });
                if (rowsAffected < 1)
                {
                    connection.Execute("INSERT INTO dbo.DasAccounts (AccountId, AccountHashId, AccountName, Balance, VersionId) " +
                                       "VALUES (@AccountId, @AccountHashId, @AccountName, @Balance, @VersionId)",
                                       new
                    {
                        AccountId     = account.Id,
                        AccountHashId = account.Id.ToString(),
                        AccountName   = $"Employer {account.Id}",
                        Balance       = account.Balance,
                        VersionId     = 1
                    });
                }
            }
        }
        internal static void UpdateAccountBalanceForPeriod(EmployerAccountReferenceData account, string period)
        {
            if (TestEnvironment.ValidateSpecsOnly)
            {
                return;
            }

            var periodBalance = account.PeriodBalances?.SingleOrDefault(x => x.PeriodName.Equals(period, System.StringComparison.CurrentCultureIgnoreCase));

            if (periodBalance == null)
            {
                return;
            }

            using (var connection = new SqlConnection(TestEnvironment.Variables.DedsDatabaseConnectionString))
            {
                connection.Execute("UPDATE dbo.DasAccounts " +
                                   "SET Balance = @Balance " +
                                   "WHERE AccountId = @AccountId ",
                                   new
                {
                    AccountId = account.Id,
                    Balance   = periodBalance.Value
                });
            }
        }
Пример #3
0
        private EmployerAccountReferenceData AddOrUpdateEmployerAccount(int id,
                                                                        decimal balance,
                                                                        List <EmployerAccountPeriodValue> periodBalances = null,
                                                                        bool isDasEmployer = true,
                                                                        bool isLevyPayer   = true)
        {
            var account = EmployerAccountContext.EmployerAccounts.SingleOrDefault(a => a.Id == id);

            if (account == null)
            {
                account = new EmployerAccountReferenceData
                {
                    Id = id
                };
                EmployerAccountContext.EmployerAccounts.Add(account);
            }

            account.Balance        = balance;
            account.PeriodBalances = periodBalances ?? new List <EmployerAccountPeriodValue>();
            account.IsDasEmployer  = isDasEmployer;
            account.IsLevyPayer    = isLevyPayer;

            EmployerAccountManager.AddOrUpdateAccount(account);

            return(account);
        }