Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            using (var dbContext = new AtmEntities())
            {
                var userRepo               = new CardHolderRepository(dbContext);
                var cardAccountRepo        = new CardAccountRepository(dbContext);
                var transactionHystoryRepo = new TransactionHistoryRepository(dbContext);
                var consoleHandler         = ConsoleHandler.Instance;
                FakeDataFiller.FillCardHoldersWithFakeData(dbContext, userRepo);
                dbContext.SaveChanges();
                consoleHandler.PrintLine("Card holders faking finished.");
                var cardHoldersIds = userRepo.GetAll().Select(u => u.Id).ToList();
                FakeDataFiller.FillCardAccountsWithFakeData(dbContext, cardAccountRepo, cardHoldersIds);
                dbContext.SaveChanges();
                consoleHandler.PrintLine("Card accounts faking finished.");

                var card = GetCredentials(cardAccountRepo);
                if (card != null)
                {
                    if (WithdrawSum(dbContext, cardAccountRepo, transactionHystoryRepo, card))
                    {
                        consoleHandler.PrintLine("Withdraw successful.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void FillCardHoldersWithFakeData(AtmEntities dbContext, CardHolderRepository userRepo)
        {
            dbContext.Configuration.AutoDetectChangesEnabled = false;
            dbContext.Configuration.ValidateOnSaveEnabled    = false;
            var randomDataProvider = new RandomDataProvider();

            int length = FakeDataCount - userRepo.GetAll().Count();

            for (int i = 0; i < length; i++)
            {
                var currentCardHolder = new CardHolder()
                {
                    Name = randomDataProvider.GetFirstName() + " " + randomDataProvider.GetStringExact(1, RandomDataType.BigLetters) + " " + randomDataProvider.GetLastName()
                };

                userRepo.Insert(currentCardHolder);

                if (i % 133 == 0) // Randomly chosen value
                {
                    dbContext.SaveChanges();
                }
            }

            dbContext.Configuration.AutoDetectChangesEnabled = true;
            dbContext.Configuration.ValidateOnSaveEnabled    = true;
        }
Ejemplo n.º 3
0
        public static void FillCardAccountsWithFakeData(AtmEntities dbContext, CardAccountRepository cardAccountsRepo, IList <int> cardHolderIds)
        {
            dbContext.Configuration.AutoDetectChangesEnabled = false;
            dbContext.Configuration.ValidateOnSaveEnabled    = false;

            var randomDataProvider    = new RandomDataProvider();
            var numberProvider        = RandomNumberProvider.GetInstance();
            var registeredCardNumbers = new HashSet <long>();
            var currentCardNumbers    = cardAccountsRepo.GetAll().Select(ca => ca.CardNumber).ToArray();
            int currentCardsCount     = 0;

            foreach (var number in currentCardNumbers)
            {
                if (string.IsNullOrEmpty(number))
                {
                    continue;
                }

                registeredCardNumbers.Add(long.Parse(number));
                currentCardsCount += 1;
            }

            int length = FakeDataCount - currentCardsCount;

            for (int i = 0; i < length; i++)
            {
                CardAccount currentCardAccount = GenerateCardAccount(registeredCardNumbers, cardHolderIds, numberProvider, randomDataProvider);

                cardAccountsRepo.Insert(currentCardAccount);

                if (i % 133 == 0) // Randomly chosen value
                {
                    dbContext.SaveChanges();
                }
            }

            dbContext.Configuration.AutoDetectChangesEnabled = true;
            dbContext.Configuration.ValidateOnSaveEnabled    = true;
        }
Ejemplo n.º 4
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (rdbTransfer.Checked)
            {
                if (counter == 0)
                {
                    counter = 1;
                }
                else
                {
                    bool sonuc = Check.ControlCustomer(lblCardNo.Text);
                    if (sonuc)
                    {
                        List <Customers> csList = GetCustomer.GetAllCustomers();
                        foreach (Customers item in csList)
                        {
                            if (item.CardNo == lblCardNo.Text)
                            {
                                List <Accounts> actList = ent.Accounts.Where(t => t.CustomerId == item.CustomerId).ToList();
                                foreach (Accounts act in actList)
                                {
                                    if (cmbAmount.Text != "")
                                    {
                                        int amount = int.Parse(cmbAmount.Text);
                                        act.Money += amount;
                                        this.Close();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Please choose a amount");
                                    }
                                }
                                int result = ent.SaveChanges();
                                if (result > 0)
                                {
                                    MessageBox.Show("Successful");
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("Error");
                                }
                            }
                        }
                    }
                }
            }
            else if (rdbWithdraw.Checked)
            {
                if (choosedAccount != null)
                {
                    int  amount = int.Parse(cmbAmount.Text);
                    bool sonuc  = Check.ControlMoney(choosedAccount, amount);
                    if (sonuc)
                    {
                        choosedAccount.Money -= amount;
                    }
                    else
                    {
                        MessageBox.Show("Not enough money");
                    }

                    int result = ent.SaveChanges();
                    if (result > 0)
                    {
                        MessageBox.Show("Successful");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please choose a operation");
            }
        }