コード例 #1
0
 private static void UserLogin(ATMContext db)
 {
     for (int i = 0; i < 6; i++)
     {
         if (i > 4)
         {
             Console.WriteLine("Too many attempts. Please try again Later");
             Environment.Exit(0);
         }
         userName = Read("Enter your username: "******"Enter your password: "******"Login Successfull");
             userInstance = db.UserInfo.Where(x => x.Username == userName).First();
             balanceInfo  = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First();
             //balanceinfo.Balance;
             break;
         }
         else
         {
             Console.WriteLine("Password or Username is incorrect please try again");
         }
     }
 }
コード例 #2
0
 private void Cash_card_btn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"];
         using (ATMContext context = new ATMContext(settings.ConnectionString))
         {
             int      money    = Convert.ToInt32(TextBox.Text);
             CardCash cardCash = new CardCash();
             string   tB       = TextBox.Text;
             if (tB == "10" || tB == "50" || tB == "100" || tB == "200" || tB == "500" || tB == "1000")
             {
                 var x = context.CardCash.Single(x => x.CardID == _cardId);
                 if (x.Cash > money)
                 {
                     x.Cash -= money;
                     context.SaveChanges();
                     MessageBox.Show("Выдача денег");
                     TextBox.Text = "";
                 }
                 else
                 {
                     MessageBox.Show($"На карт не достаточно средств!\n Баланс на карте: {cardAtmRepository.GetBalanse(_cardId)}");
                 }
             }
             else
             {
                 MessageBox.Show("Банкомат может выддат только 10,50,100,200,500,1000");
             }
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #3
0
        static void Main(string[] args)
        {
            using (var db = new ATMContext())
            {
                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("1) Login");
                    Console.WriteLine("2) Create an Account");
                    int choice = int.Parse(Read("> "));

                    switch (choice)
                    {
                    case 1:
                        UserLogin(db);
                        AccountManagement(db);
                        break;

                    case 2:
                        NewUser(db);
                        AccountCreation(db);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #4
0
        private static void Withdraw(ATMContext db)
        {
            userInstance = db.UserInfo.Where(x => x.Username == userName).First();
            balanceInfo  = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First();
            double balance        = balanceInfo.Balance;
            var    withdraw       = Read("How much would you like to withdraw? : ");
            double withdrawAmount = int.Parse(withdraw);
            double newBalance;

            if (withdrawAmount > balance)
            {
                Console.WriteLine("You overdrew your account. You will be charged a $15 fee.");
                double overdrawnBalance = withdrawAmount + 15;
                newBalance = balance - overdrawnBalance;
            }
            else
            {
                newBalance = balance - withdrawAmount;
            }
            AccountInfo accountInfo = new AccountInfo
            {
                Balance  = newBalance,
                Withdraw = withdrawAmount,
                UserInfo = userInstance,
                DateTime = DateTime.Now,
            };

            db.AccountInfo.Add(accountInfo);
            db.SaveChanges();
            Console.WriteLine($" Your new account balance is ${newBalance}");
        }
コード例 #5
0
        private static void Transfer(ATMContext db)
        {
            userName = Read("Enter the name of the account you would like to transfer to: ");
            bool userNameTrue = db.UserInfo.Any(u => u.Username == (userName));

            while (userNameTrue == false)
            {
                Console.WriteLine("That user does not exist.");
                userName     = Read("Enter the name of the account you would like to transfer to: ");
                userNameTrue = db.UserInfo.Any(u => u.Username == (userName));
            }
            userInstance = db.UserInfo.Where(x => x.Username == userName).First();
            balanceInfo  = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First();
            double      balanceTransfer      = balanceInfo.Balance;
            var         deposit              = Read("How much would you like to Transfer?: ");
            double      depositAmount        = int.Parse(deposit);
            double      newBalanceTransferTO = depositAmount + balanceTransfer;
            AccountInfo accountInfo          = new AccountInfo
            {
                Balance  = newBalanceTransferTO,
                Deposit  = depositAmount,
                UserInfo = userInstance,
                DateTime = DateTime.Now,
            };

            db.AccountInfo.Add(accountInfo);
            db.SaveChanges();

            Console.WriteLine("Please verify your account information to make the transfer.");
            UserLogin(db);
            double balance        = balanceInfo.Balance;
            var    withdraw       = deposit;
            double withdrawAmount = int.Parse(withdraw);
            double newBalance;

            if (withdrawAmount > balance)
            {
                Console.WriteLine("You overdrew your account. You will be charged a $15 fee.");
                double overdrawnBalance = withdrawAmount + 15;
                newBalance = balance - overdrawnBalance;
            }
            else
            {
                newBalance = balance - withdrawAmount;
            }
            AccountInfo accountInfo2 = new AccountInfo
            {
                Balance  = newBalance,
                Withdraw = withdrawAmount,
                UserInfo = userInstance,
                DateTime = DateTime.Now,
            };

            db.AccountInfo.Add(accountInfo2);
            db.SaveChanges();
            Console.WriteLine($" Your new account balance is ${newBalance}");
            Pause();
        }
コード例 #6
0
        private static void AccountActivity(ATMContext db)
        {
            bool logCK = true;

            while (logCK)
            {
                userInstance = db.UserInfo.Where(x => x.Username == userName).First();
                balanceInfo  = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First();
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("1) Check Balance");
                Console.WriteLine("2) Withdraw Activity");
                Console.WriteLine("3) Deposit Activity");
                Console.WriteLine("4) Back");
                int choice = int.Parse(Read("> "));

                switch (choice)
                {
                case 1:
                    Console.WriteLine($"Your Current Balance: ${balanceInfo.Balance}");
                    Pause();
                    break;

                case 2:
                    var allWithdrawInfo = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id);
                    foreach (var withdraw in allWithdrawInfo)
                    {
                        Console.WriteLine($"You Withdrew: ${withdraw.Withdraw} On   {withdraw.DateTime }");
                    }
                    Pause();
                    break;

                case 3:
                    var allDepositInfo = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id);
                    foreach (var Deposit in allDepositInfo)
                    {
                        Console.WriteLine($"You Deposited: ${Deposit.Deposit} On   {Deposit.DateTime }");
                    }
                    Pause();
                    break;

                case 4:
                    logCK = false;
                    break;

                default:
                    break;
                }
            }
        }
コード例 #7
0
        private static void AccountCreation(ATMContext db)
        {
            AccountInfo accountInfo = new AccountInfo
            {
                Balance  = 0,
                Withdraw = 0,
                Deposit  = 0,
                DateTime = DateTime.Now,
                UserInfo = userInstanceNewAcc,
            };

            db.AccountInfo.Add(accountInfo);
            db.SaveChanges();
        }
コード例 #8
0
ファイル: MainWindow.xaml.cs プロジェクト: ilyamoroz/ATM
        public void CreateCard()
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"];

            using (ATMContext context = new ATMContext(settings.ConnectionString))
            {
                Card card = new Card();
                card.Number = "1234528415234582";
                context.Cards.Add(card);
                context.SaveChanges();
                PINCode pin = new PINCode();
                pin.CardID = 1;
                pin.Code   = GetCodeHash("1234");
                context.PINCodes.Add(pin);
                context.SaveChanges();
            }
        }
コード例 #9
0
        private static void AccountManagement(ATMContext db)
        {
            bool logCK = true;

            while (logCK)
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("1) Make a Withdraw");
                Console.WriteLine("2) Deposit Money");
                Console.WriteLine("3) Account Activity");
                Console.WriteLine("4) Transfer Money");
                Console.WriteLine("5) Logout");
                int choice = int.Parse(Read("> "));

                switch (choice)
                {
                case 1:
                    Withdraw(db);
                    Pause();
                    break;

                case 2:
                    Deposit(db);
                    Pause();
                    break;

                case 3:
                    AccountActivity(db);
                    break;

                case 4:
                    Transfer(db);
                    break;

                case 5:
                    logCK = false;
                    break;

                default:
                    break;
                }
            }
        }
コード例 #10
0
        private static void Deposit(ATMContext db)
        {
            userInstance = db.UserInfo.Where(x => x.Username == userName).First();
            balanceInfo  = db.AccountInfo.Where(y => y.UserInfo.Id == userInstance.Id).OrderByDescending(x => x.Id).First();
            double balance       = balanceInfo.Balance;
            var    deposit       = Read("How much would you like to Deposit? : ");
            double depositAmount = int.Parse(deposit);
            double newBalance;

            newBalance = depositAmount + balance;
            AccountInfo accountInfo = new AccountInfo
            {
                Balance  = newBalance,
                Deposit  = depositAmount,
                UserInfo = userInstance,
                DateTime = DateTime.Now,
            };

            db.AccountInfo.Add(accountInfo);
            db.SaveChanges();
            Console.WriteLine($" Your new account balance is ${newBalance}");
        }
コード例 #11
0
        private static void NewUser(ATMContext db)
        {
            var  userName     = Read("Enter a new username: "******"That Username is already taken.");
                userName     = Read("Enter a new username: "******"Enter a password: ");
            UserInfo userInfo = new UserInfo
            {
                Username     = userName,
                Password     = password,
                JoinDateTime = DateTime.Now,
            };

            db.UserInfo.Add(userInfo);
            db.SaveChanges();
            userInstanceNewAcc = db.UserInfo.Where(x => x.Username == userName).First();
        }
コード例 #12
0
 public ATMRepository(ATMContext context)
 {
     _context = context;
 }