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; }
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."); } } } }
private static bool WithdrawSum( AtmEntities dbContext, CardAccountRepository cardAcountRepo, TransactionHistoryRepository tarnsactionHystoryRepo, ICardAccount cardAccount) { var transactionsHandler = new TransactionsHandler(dbContext, cardAcountRepo, tarnsactionHystoryRepo); var consoleHandler = ConsoleHandler.Instance; consoleHandler.Print("Enter value to withdraw: "); var withdrawValueInput = consoleHandler.GetStringInput(); decimal withdrawValue = new decimal(); if(!decimal.TryParse(withdrawValueInput, out withdrawValue)) { return false; } return transactionsHandler.WithdrawTransaction(cardAccount.CardNumber, cardAccount.CardPin, withdrawValue); }
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; }