Example #1
0
        public static void UpdateTransactionsHistory(AtmContext atmContext, CardAccount account, decimal oldCash, decimal newCash)
        {
            TransactionScope transaction = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions()
            {
                // Nested transactions must have the same isolation level
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            using (transaction)
            {
                TransactionsHistory tranHistory = new TransactionsHistory()
                {
                    CardAccount = account,
                    OldCash     = oldCash,
                    NewCash     = newCash
                };

                atmContext.TransactionsHistories.Add(tranHistory);
                atmContext.SaveChanges();

                transaction.Complete();
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            Database.SetInitializer <ATMSystemContext>(null);
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <ATMSystemContext, Configuration>());
            var db = new ATMSystemContext();

            Console.Write("Enter the Card ID to withdraw from: ");
            int cardId = int.Parse(Console.ReadLine());

            Console.Write("Enter the amount: ");
            decimal amount = int.Parse(Console.ReadLine());

            // not working - see description bellow
            //string trigger = CreateTriggerString();
            //db.Database.ExecuteSqlCommand(trigger);

            // RepeatableRead isolation level will lock all the fields that have been read during transaction
            // this will asure data consistency after transaction is commited
            using (DbContextTransaction dbTransaction = db.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
            {
                try
                {
                    var card = db.CardAccounts.FirstOrDefault(c => c.CardAccountId == cardId);
                    var cardInitialAmount = card.CardCash;
                    TransactionsHistory transactionLog = new TransactionsHistory();
                    transactionLog.Ammount         = amount;
                    transactionLog.TransactionDate = DateTime.Now;
                    transactionLog.CardAccountId   = card.CardAccountId;

                    Console.WriteLine("Before transaction");
                    PrintCardDetails(card);

                    bool cardExist          = card != null;
                    bool cardHasEnoughMoney = cardInitialAmount >= amount;

                    if (cardHasEnoughMoney)
                    {
                        card.CardCash -= amount;
                        db.TransactionsHistories.Add(transactionLog);
                        db.SaveChanges();
                        dbTransaction.Commit();
                    }
                    else
                    {
                        Console.WriteLine("No enough money in account. No transaction implemented!");
                    }

                    Console.WriteLine("\nAfter transaction");
                    PrintCardDetails(card);
                }
                catch (Exception)
                {
                    Console.WriteLine("Wrong account number! Unsuccesful trnsaction!");
                    dbTransaction.Rollback();
                }
            }
        }
Example #3
0
        private void Log(string cardNumber, decimal ammount)
        {
            var history = new TransactionsHistory()
            {
                CardNumber      = cardNumber,
                TransactionDate = DateTime.Now,
                Ammount         = ammount
            };

            this.data.TransactionsHistories.Add(history);
        }
Example #4
0
        public static void CashWithdraw(string cardNumber,
                                        string cardPin, decimal sum)
        {
            using (var db = new ATMContext())
            {
                bool success = false;
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        // get card number and pin
                        var card = db.CardAccounts.
                                   Where(c => c.CardNumber == cardNumber).
                                   Where(p => p.CardPin == cardPin).First();

                        if (card.CardCash >= sum)
                        {
                            // withdraw sum
                            card.CardCash -= sum;
                        }
                        else
                        {
                            Console.WriteLine("Insufficient funds!");
                        }

                        transaction.Complete();
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Wrong PIN or Invalid card!");
                    }
                }
                if (success)
                {
                    // save in history
                    var log = new TransactionsHistory()
                    {
                        CardNumber      = cardNumber,
                        TransactionDate = DateTime.Now,
                        Ammount         = sum
                    };

                    db.TransactionsHisory.Add(log);

                    db.SaveChanges();
                    Console.WriteLine("Transaction successful!");
                }
            }
        }
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<ATMContext, Configuration>());
            var context = new ATMContext();

            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    Console.Write("Please, enter card number: ");
                    var cardNumber = Console.ReadLine();

                    Console.Write("Please, enter PIN: ");
                    var pinCode = Console.ReadLine();

                    var account = ATMManager.GetAccount(context, cardNumber, pinCode);

                    Console.Write("Please, enter amount: ");
                    var amount = decimal.Parse(Console.ReadLine());

                    ATMManager.ValidateAccountAmount(account, amount);
                    account.CardCash -= amount;

                    var transaction = new TransactionsHistory()
                    {
                        CardNumber = cardNumber,
                        Amount = amount,
                        TransactionDate = DateTime.Now
                    };

                    context.TransactionHistories.Add(transaction);
                    context.SaveChanges();
                    dbContextTransaction.Commit();

                    Console.WriteLine("Withdraw complete.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    dbContextTransaction.Rollback();
                }
            }
        }
Example #6
0
        public void Update()
        {
            //Arrange
            var history = new TransactionsHistory()
            {
                Id = 1
            };
            var historyRepository = new MockIRepository <TransactionsHistory>()
                                    .MockUpdate(history);
            var historyService = new HistoryService(
                historyRepository.Object,
                null,
                new MockIRepository <Account>().Object);

            //Act
            var updatedHistory = historyService.Update(history);

            //Assert
            Assert.IsNotNull(updatedHistory);
        }
Example #7
0
        public void GetById()
        {
            //Arrange
            var history = new TransactionsHistory()
            {
                Id = 1
            };
            var historyRepository = new MockIRepository <TransactionsHistory>()
                                    .MockGetById(history);
            var historyService = new HistoryService(
                historyRepository.Object,
                null,
                new MockIRepository <Account>().Object);

            //Act
            var historyById = historyService.GetById(1);

            //Assert
            Assert.IsNotNull(historyById);
        }
Example #8
0
        private void SaveTransactionHistory(string cardNumber, decimal amount)
        {
            var options = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.RepeatableRead,
                Timeout        = new TimeSpan(0, 0, 0, 10)
            };

            using (var scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                TransactionsHistory transactionInfo = new TransactionsHistory
                {
                    CardNumber      = cardNumber,
                    TransactionDate = DateTime.Now,
                    Amount          = amount
                };

                this.atmContext.TransactionsHistories.Add(transactionInfo);
                this.atmContext.SaveChanges();

                scope.Complete();
            }
        }
Example #9
0
        public async Task Seed()
        {
            var user = await _userManager.FindByNameAsync("admin");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "78945612",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "ItAcademy",
                        City       = "Tbilisi",
                        FirstName  = "Admin",
                        LastName   = "Adminashvili",
                        PassportId = "555777888",
                        Sex        = "Male",
                        ImageName  = "A.png"
                    },

                    LoginReports = new List <LoginReport>
                    {
                        new LoginReport
                        {
                            LastLogin     = DateTime.Now,
                            FirstLogin    = DateTime.Now,
                            AvgPerday     = 1,
                            PerMonth      = 30,
                            CounterLogsIn = 30,
                        }
                    }
                }, "asdASD123!@#");
            }
            var role = await _roleManager.FindByNameAsync("Admin");

            if (role == null)
            {
                await _roleManager.CreateAsync(new IdentityRole <int>() { Name = "Admin" });

                var createdAdmin = await _userManager.FindByNameAsync("admin");

                await _userManager.AddToRoleAsync(createdAdmin, "Admin");
            }

            user = await _userManager.FindByNameAsync("Andrii");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "14881488",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Gldanula",
                        City       = "Gldanopolis",
                        FirstName  = "Andrii",
                        LastName   = "Turianskyi",
                        PassportId = "123456789",
                        Sex        = "Male",
                        ImageName  = "A.png"
                    }
                }, "asdASD123!@#");
            }

            user = await _userManager.FindByNameAsync("Jimmy");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "197345682",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Plato",
                        City       = "JimmyWown",
                        FirstName  = "Jimmy",
                        LastName   = "Page",
                        PassportId = "1000101",
                        Sex        = "Male",
                        ImageName  = "jimmy.png"
                    }
                }, "asdASD123!@#");
            }

            user = await _userManager.FindByNameAsync("John");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "15978453",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Foreignstan",
                        City       = "Cityburg",
                        FirstName  = "John",
                        LastName   = "Bergmann",
                        PassportId = "5558888777",
                        Sex        = "Male",
                        ImageName  = "J.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Irinka");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "11111222",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Gagarini",
                        City       = "Tbilisi",
                        FirstName  = "Irinka",
                        LastName   = "Inashvili",
                        PassportId = "1000103",
                        Sex        = "Female",
                        ImageName  = "I.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Vano");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "5554445",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Vazisubani",
                        City       = "Tbilisi",
                        FirstName  = "Vano",
                        LastName   = "Tsiklauri",
                        PassportId = "1000104",
                        Sex        = "Male",
                        ImageName  = "V.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Nini");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "4448444",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Makhata",
                        City       = "Tbilisi",
                        FirstName  = "Nini",
                        LastName   = "Kurtanidze",
                        PassportId = "1000105",
                        Sex        = "Female",
                        ImageName  = "N.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Aleksandre");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "4777585",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Uznadze",
                        City       = "Tbilisi",
                        FirstName  = "Aleksandre",
                        LastName   = "Gabelashvili",
                        PassportId = "1000106",
                        Sex        = "Male",
                        ImageName  = "A.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Sergii");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "48878789",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Politkovskaya",
                        City       = "Kyiv",
                        FirstName  = "Sergii",
                        LastName   = "Kovach",
                        PassportId = "1000107",
                        Sex        = "Male",
                        ImageName  = "S.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Natali");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "8888877",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Sarajishvili",
                        City       = "Akhalkalaki",
                        FirstName  = "Natali",
                        LastName   = "Japaridze",
                        PassportId = "1000108",
                        Sex        = "Female",
                        ImageName  = "N.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Anna");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "30002001",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Guramishvili",
                        City       = "Tbilisi",
                        FirstName  = "Anna",
                        LastName   = "Zakaidze",
                        PassportId = "1000109",
                        Sex        = "Female",
                        ImageName  = "A.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Giga");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "70707080",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Marjanishvili",
                        City       = "Tbilisi",
                        FirstName  = "Giga",
                        LastName   = "Baidoshvili",
                        PassportId = "1000111",
                        Sex        = "Male",
                        ImageName  = "G.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Shota");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "125554445",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Saburtalo",
                        City       = "Tbilisi",
                        FirstName  = "Shota",
                        LastName   = "Gotsadze",
                        PassportId = "1000112",
                        Sex        = "Male",
                        ImageName  = "S.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Tamari");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "11145454",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Nojikhevi",
                        City       = "Zugdidi",
                        FirstName  = "Tamar",
                        LastName   = "Nasrashvili",
                        PassportId = "1000113",
                        Sex        = "Female",
                        ImageName  = "T.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Nana");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "99996523",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Sarajishvili",
                        City       = "Tbilisi",
                        FirstName  = "Nana",
                        LastName   = "Rogava",
                        PassportId = "1000114",
                        Sex        = "Female",
                        ImageName  = "N.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Nika");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "550040040",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Varketili",
                        City       = "Tbilisi",
                        FirstName  = "Nika",
                        LastName   = "Tsivilashvili",
                        PassportId = "1000115",
                        Sex        = "Male",
                        ImageName  = "N.png"
                    }
                }, "asdASD123!@#");
            }
            user = await _userManager.FindByNameAsync("Tatia");

            if (user == null)
            {
                await _userManager.CreateAsync(new User()
                {
                    UserName    = "******",
                    Email       = "*****@*****.**",
                    PhoneNumber = "599797998",
                    UserInfo    = new UserInfo()
                    {
                        Address    = "Konstitucia",
                        City       = "Rustavi",
                        FirstName  = "Tatia",
                        LastName   = "Sebiskveradze",
                        PassportId = "1000116",
                        Sex        = "Female",
                        ImageName  = "T.png"
                    }
                }, "asdASD123!@#");
            }

            var existingAccounts = _context.Accounts.Where(x => x.AccountName == "johnAcc" || x.AccountName == "andriiAcc").ToList();

            if (existingAccounts != null && existingAccounts.Count != 0)
            {
                return;
            }

            _context.Database.EnsureCreated();

            var transaction = new TransactionsHistory()
            {
                Date        = DateTime.Now,
                Currency    = "USD",
                Amount      = 100,
                Description = "Sending someone some money",
            };

            var accountDeposit1 = new AccountDeposit()
            {
                Status        = Status.IsActive.ToString(),
                DepositAmount = 100,
                AccountId     = 1,
                Term          = typeof(Term).GetValues().ToArray()[0]
            };

            var accountDeposit2 = new AccountDeposit()
            {
                Status        = Status.Pending.ToString(),
                DepositAmount = 100,
                AccountId     = 2,
                Term          = typeof(Term).GetValues().ToArray()[1]
            };

            var accountDeposit3 = new AccountDeposit()
            {
                Status        = Status.Pending.ToString(),
                DepositAmount = 5000,
                AccountId     = 3,
                Term          = typeof(Term).GetValues().ToArray()[2]
            };

            _context.Deposits.Add(new Deposit()
            {
                Annual              = 20,
                Benefits            = 0,
                Bonus               = 0,
                Description         = "Some deposit",
                InterestPaymentDate = new DateTime(2000, 01, 01),
                MaxAMount           = 5000,
                MinAmount           = 200,
                Name            = "Deposit01",
                Replenishment   = 0,
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit1
                },
                Currency     = "USD",
                InterestRate = 3
            });

            _context.Deposits.Add(new Deposit()
            {
                Annual              = 20,
                Benefits            = 0,
                Bonus               = 0,
                Description         = "Some deposit",
                InterestPaymentDate = new DateTime(2000, 01, 01),
                MaxAMount           = 7000,
                MinAmount           = 1000,
                Name            = "Deposit02",
                Replenishment   = 0,
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit2
                },
                Currency     = "USD",
                InterestRate = 2
            });

            _context.Deposits.Add(new Deposit()
            {
                Annual              = 20,
                Benefits            = 0,
                Bonus               = 0,
                Description         = "Some deposit",
                InterestPaymentDate = new DateTime(2000, 01, 01),
                MaxAMount           = 2000,
                MinAmount           = 300,
                Name            = "Deposit03",
                Replenishment   = 0,
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit3
                },
                Currency     = "USD",
                InterestRate = 1
            });

            var accountLoan1 = new AccountLoan()
            {
                Currency   = "USD",
                Status     = Status.IsActive.ToString(),
                Sum        = 2000,
                Term       = typeof(Term).GetValues().ToArray()[1],
                Employment = "SomePosition"
            };

            var accountLoan2 = new AccountLoan()
            {
                Currency   = "USD",
                Status     = Status.Pending.ToString(),
                Sum        = 2000,
                Term       = typeof(Term).GetValues().ToArray()[2],
                Employment = "SomePosition"
            };

            var accountLoan3 = new AccountLoan()
            {
                Currency   = "USD",
                Status     = Status.Pending.ToString(),
                Sum        = 2000,
                Term       = typeof(Term).GetValues().ToArray()[0],
                Employment = "SomePosition"
            };

            _context.Accounts.Add(
                new Account()
            {
                UserId        = (await _userManager.FindByNameAsync("admin")).Id,
                AccountNumber = "123BANK123",
                AccountName   = "BankBalance",
                Balance       = 10000000000
            }
                );

            _context.Accounts.Add(
                new Account()
            {
                UserId        = (await _userManager.FindByNameAsync("Andrii")).Id,
                AccountNumber = "98745612358",
                AccountName   = "andriiAcc",
                Balance       = 200000,
                Cards         = new List <Card>
                {
                    new Card()
                    {
                        CardNumber = _encryptionService.Encrypt("5987458521365478"),
                        CCV        = 985,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Active.ToString(),
                        CardType   = "MasterCard"
                    },

                    new Card()
                    {
                        CardNumber = _encryptionService.Encrypt("5987458521365479"),
                        CCV        = 985,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Active.ToString(),
                        CardType   = "MasterCard"
                    },

                    new Card()
                    {
                        CardNumber = _encryptionService.Encrypt("5987458521365470"),
                        CCV        = 985,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Active.ToString(),
                        CardType   = "MasterCard"
                    }
                },
                AccountLoans = new List <AccountLoan>
                {
                    accountLoan1, accountLoan2
                },
                AccrueAccountLoans = new List <AccountLoan>
                {
                    accountLoan1, accountLoan3
                },
                Transactions = new List <TransactionsHistory>
                {
                    transaction
                },
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit3
                },
            }
                );

            _context.Accounts.Add(
                new Account()
            {
                UserId        = (await _userManager.FindByNameAsync("Jimmy")).Id,
                AccountNumber = "123456789",
                AccountName   = "JimmyAcc",
                Balance       = 10000,
                Cards         = new List <Card>
                {
                    new Card()
                    {
                        CardNumber = _encryptionService.Encrypt("5987458511365478"),
                        CCV        = 123,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Pending.ToString(),
                        CardType   = CardTypes.MasterCard.ToString()
                    },
                    new Card()
                    {
                        CardNumber = _encryptionService.Encrypt("5987458511365478"),
                        CCV        = 339,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Pending.ToString(),
                        CardType   = CardTypes.Visa.ToString()
                    },
                },
                AccountLoans = new List <AccountLoan>
                {
                    accountLoan1, accountLoan2
                },
                AccrueAccountLoans = new List <AccountLoan>
                {
                    accountLoan1, accountLoan3
                },
                Transactions = new List <TransactionsHistory>
                {
                    transaction
                },
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit3
                },
            }
                );

            _context.Accounts.Add(
                new Account()
            {
                UserId        = (await _userManager.FindByNameAsync("John")).Id,
                AccountNumber = "555666111222",
                AccountName   = "johnAcc",
                Balance       = 200,
                Cards         = new List <Card>
                {
                    new Card()
                    {
                        AccountId  = 1,
                        CardNumber = _encryptionService.Encrypt("2589854785986525"),
                        CCV        = 229,
                        CreatedAt  = DateTime.Now,
                        ExpireDate = DateTime.Now.AddYears(3),
                        Status     = CardStatus.Active.ToString(),
                        CardType   = "Visa"
                    }
                },
                AccountDeposits = new List <AccountDeposit>
                {
                    accountDeposit1, accountDeposit2
                },
                MoneyTransfers = new List <TransactionsHistory>
                {
                    transaction
                },
                AccountLoans = new List <AccountLoan>
                {
                    accountLoan3
                },
                AccrueAccountLoans = new List <AccountLoan>
                {
                    accountLoan2
                },
            }
                );

            _context.Loans.Add(new Loan()
            {
                Name              = "TestLoan1",
                Percentage        = 18,
                ServiceFee        = 2,
                AccidentInsurance = 0,
                InsuranceLoan     = 0,
                AccountLoans      = new List <AccountLoan>
                {
                    accountLoan1
                },
                Currency          = "USD",
                InterestRate      = 3,
                LoanInterestRate  = 3,
                RepaymentSchedule = "Monthly",
                AdvancedPayment   = "Without paying commission",
                MinAmount         = 2000,
                MaxAmount         = 5000,
                Term    = typeof(Term).GetValues().ToArray()[0],
                Purpose = typeof(LoanPurposes).GetValues().ToArray()[0]
            });

            _context.Loans.Add(new Loan()
            {
                Name              = "TestLoan2",
                Percentage        = 18,
                ServiceFee        = 2,
                AccidentInsurance = 0,
                InsuranceLoan     = 200,
                AccountLoans      = new List <AccountLoan>
                {
                    accountLoan2
                },
                Currency          = "USD",
                InterestRate      = 10,
                LoanInterestRate  = 10,
                RepaymentSchedule = "Monthly",
                AdvancedPayment   = "Without paying commission",
                MinAmount         = 3000,
                MaxAmount         = 6000,
                Term    = typeof(Term).GetValues().ToArray()[1],
                Purpose = typeof(LoanPurposes).GetValues().ToArray()[1]
            });

            _context.Loans.Add(new Loan()
            {
                Name              = "TestLoan3",
                Percentage        = 18,
                ServiceFee        = 2,
                AccidentInsurance = 0,
                InsuranceLoan     = 156,
                AccountLoans      = new List <AccountLoan>
                {
                    accountLoan3
                },
                Currency          = "USD",
                InterestRate      = 20,
                LoanInterestRate  = 20,
                RepaymentSchedule = "Monthly",
                AdvancedPayment   = "Without paying commission",
                MinAmount         = 5000,
                MaxAmount         = 100000,
                Term    = typeof(Term).GetValues().ToArray()[2],
                Purpose = typeof(LoanPurposes).GetValues().ToArray()[2]
            });

            await _context.SaveChangesAsync();
        }
Example #10
0
 private static void AddToHistory(string cNumber, DateTime transactionTime, decimal money, ATMContext db)
 {
     using (db)
     {
         using (var tran = new TransactionScope())
         {
             var history = new TransactionsHistory(cNumber, transactionTime, money);
             db.TransactionsHistories.Add(history);
             db.SaveChanges();
             tran.Complete();
             Console.WriteLine("added");
         }
     }
 }
Example #11
0
        public async Task <TransactionsHistory> Update(TransactionsHistory history)
        {
            var result = await _transactionsHistories.Update(history);

            return(result);
        }
Example #12
0
 public async Task Delete(TransactionsHistory history)
 {
     await _transactionsHistories.Delete(history);
 }
Example #13
0
        public static void CashWithdraw(string cardNumber,
            string cardPin, decimal sum)
        {
            using (var db = new ATMContext())
            {
                bool success = false;
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        // get card number and pin
                        var card = db.CardAccounts.
                            Where(c => c.CardNumber == cardNumber).
                            Where(p => p.CardPin == cardPin).First();

                        if (card.CardCash >= sum)
                        {
                            // withdraw sum
                            card.CardCash -= sum;
                        }
                        else
                        {
                            Console.WriteLine("Insufficient funds!");
                        }

                        transaction.Complete();
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Wrong PIN or Invalid card!");
                    }
                }
                if (success)
                {
                    // save in history
                    var log = new TransactionsHistory()
                    {
                        CardNumber = cardNumber,
                        TransactionDate = DateTime.Now,
                        Ammount = sum
                    };

                    db.TransactionsHisory.Add(log);

                    db.SaveChanges();
                    Console.WriteLine("Transaction successful!");
                }
            }
        }