예제 #1
0
        public void WithdrawMoney(double amount)
        {
            int     client_id     = ID;
            string  queryString1  = $"SELECT amount FROM CurrentAccounts WHERE client_id={ client_id};";
            decimal currentAmount = ConnectionDB.ReturnDecimal(queryString1);

            string  queryString2 = $"SELECT overdraft FROM CurrentAccounts WHERE client_id={ client_id};";
            decimal overdraft    = ConnectionDB.ReturnDecimal(queryString2);

            string queryString3     = $"SELECT id FROM CurrentAccounts WHERE client_id={ client_id};";
            int    currentAccountID = ConnectionDB.ReturnID(queryString3);

            if (Convert.ToDouble(currentAmount - overdraft) >= amount)
            {
                DateTime dateOp      = DateTime.Now;
                string   queryString = $"UPDATE CurrentAccounts SET amount = (amount - {amount}) WHERE  client_id = {  client_id }; " +
                                       $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, amount, executionDate, \"status\") " +
                                       $"VALUES({currentAccountID}, 'withdraw', {amount}, '{dateOp}', \'done\')";
                ConnectionDB.NonQuerySQL(queryString);
            }
            else
            {
                Console.WriteLine("Not enough money on current account.");
            }
        }
예제 #2
0
        public void EmptyCurrentAccount(int client_id, int destinaryAccount)
        {
            string          queryString = $"SELECT amount FROM CurrentAccounts WHERE client_id = {client_id};";
            double          amount      = (double)ConnectionDB.ReturnDecimal(queryString);
            string          queryStringGetCurrentAccountId = $"SELECT id FROM CurrentAccounts WHERE client_id = {client_id};";
            int             currentAccountId = ConnectionDB.ReturnID(queryStringGetCurrentAccountId);
            InstantTransfer instant          = new InstantTransfer();

            instant.RecordTransferFromCurrentToCurrent(currentAccountId, destinaryAccount, amount);
        }
예제 #3
0
        public void EmptySavingAccount(int client_id)
        {
            List <int> idSavingAccount = ConnectionDB.GetSavingAccountIds(client_id);
            string     queryStringGetCurrentAccountId = $"SELECT id FROM CurrentAccounts WHERE client_id = {client_id}";
            int        currentAccountId = ConnectionDB.ReturnID(queryStringGetCurrentAccountId);

            foreach (int id in idSavingAccount)
            {
                string          queryString = $"SELECT amount FROM SavingAccounts WHERE id = {id};";
                double          amount      = (double)ConnectionDB.ReturnDecimal(queryString);
                InstantTransfer instant     = new InstantTransfer();
                instant.RecordTransferFromSavingToCurrent(id, currentAccountId, amount);
            }
        }
예제 #4
0
        public void QueryTransferFromSavingToCurrent(int emitterId, int beneficiaryId, double amount, DateTime executionDate)
        {
            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {emitterId}";
            decimal savingAccountAmount       = ConnectionDB.ReturnDecimal(checkSavingAccountContent);

            if ((Convert.ToDouble(savingAccountAmount) - amount) >= 0)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (savingAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"\'Money Transfer\', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"\'{executionDate}\'," +
                    $"\'pending\');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }
예제 #5
0
        public void QueryTransferFromCurrentToSaving(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            string  checkCurrentAccountContent = $"SELECT amount FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountContent      = ConnectionDB.ReturnDecimal(checkCurrentAccountContent);
            string  getCurrentAccountOverdraft = $"SELECT overdraft FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountOverdraft    = ConnectionDB.ReturnDecimal(getCurrentAccountOverdraft);

            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {beneficiaryId}";
            decimal SavingAccountContent      = ConnectionDB.ReturnDecimal(checkSavingAccountContent);
            string  checkSavingAccountCeiling = $"SELECT ceiling FROM SavingAccounts WHERE id = {beneficiaryId}";
            decimal SavingAccountCeiling      = ConnectionDB.ReturnDecimal(checkSavingAccountCeiling);

            bool IsValidDonator = Client.AddFromBeneficiary(emitterId, beneficiaryId);

            if (Convert.ToDouble(CurrentAccountContent - CurrentAccountOverdraft) >= amount && IsValidDonator)
            {
                if (((Convert.ToDouble(SavingAccountContent)) + amount) < Convert.ToDouble(SavingAccountCeiling))
                {
                    string queryString =
                        $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, beneficiarySavingAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                        $"VALUES (" +
                        $"{emitterId}, " +
                        $"'Money Transfer', " +
                        $"{beneficiaryId}, " +
                        $"{amount}, " +
                        $"'{firstExecution}'," +
                        $"'{lastExecution}'," +
                        $"{interval}," +
                        $"'pending');";
                    ConnectionDB.NonQuerySQL(queryString);
                }
                else
                {
                    Console.WriteLine($"Impossible transfer. Transfer would exceed ceiling limit.");
                }
            }
            else
            {
                Console.WriteLine($"There is not enough money on current account to perform transfer");
            }
        }
예제 #6
0
        public void QueryTransferFromSavingToCurrent(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {emitterId}";
            decimal SavingAccountContent      = ConnectionDB.ReturnDecimal(checkSavingAccountContent);

            if ((Convert.ToDouble(SavingAccountContent) - amount) >= 0)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (savingAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"'Money Transfer', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"'{firstExecution}'," +
                    $"'{lastExecution}'," +
                    $"{interval}," +
                    $"'pending');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }
예제 #7
0
        public void QueryTransferFromCurrentToCurrent(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            int     debitClient_id             = Person.ID;
            string  checkCurrentAccountContent = $"SELECT amount FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountContent      = ConnectionDB.ReturnDecimal(checkCurrentAccountContent);
            string  getCurrentAccountOverdraft = $"SELECT overdraft FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountOverdraft    = ConnectionDB.ReturnDecimal(getCurrentAccountOverdraft);

            if (Convert.ToDouble(CurrentAccountContent + CurrentAccountOverdraft) > amount)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"'Money Transfer', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"'{firstExecution}'," +
                    $"'{lastExecution}'," +
                    $"{interval}," +
                    $"'pending');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }