private static void InsertSampleData(ATMSystemContext context) { var account = new CardAccount() { CardCash = 300, CardNumber = "123", CardPIN = "80801", }; context.CardAccounts.Add(account); var account2 = new CardAccount() { CardCash = 350, CardNumber = "1234", CardPIN = "80802", }; context.CardAccounts.Add(account2); var account3 = new CardAccount() { CardCash = 400, CardNumber = "1235", CardPIN = "80803", }; context.CardAccounts.Add(account3); context.SaveChanges(); }
private static void InitialDataImport() { using (var db = new ATMContext()) { var account1 = new CardAccount { CardNumber = "1234567893", CardPin = "1234", CardCash = 5000.00m }; var account2 = new CardAccount { CardNumber = "1234567894", CardPin = "2234", CardCash = 5000.00m }; var account3 = new CardAccount { CardNumber = "1234567895", CardPin = "3234", CardCash = 5000.00m }; db.CardAccounts.Add(account1); db.CardAccounts.Add(account2); db.CardAccounts.Add(account3); db.SaveChanges(); db.Database.ExecuteSqlCommand("CREATE UNIQUE INDEX IX_CardNumber ON CardAccounts (CardNumber)"); } }
private void ValidateCreateCardAccount(CardAccount cardAccount) { if (String.IsNullOrEmpty(cardAccount.UserId)) { throw new ValidationException("Field UserId should not be empty"); } }
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(); } }
private static CardAccount GenerateCardAccount(HashSet <long> registeredCardNumbers, IList <int> cardHolderIds, IRandomNumberProvider numberProvider, IRandomDataProvider randomDataProvider) { string cardNumber = string.Empty; long number = new long(); while (number == 0 || registeredCardNumbers.Contains(number)) { number = (long)numberProvider.GetIntInRange(0, 1999999999) * (long)numberProvider.GetIntInRange(1, 5); } registeredCardNumbers.Add(number); cardNumber = number.ToString().PadLeft(10, '0'); var holderId = cardHolderIds[numberProvider.GetIntUpTo(cardHolderIds.Count - 1)]; var pin = randomDataProvider.GetStringExact(4, RandomDataType.Numerics); var cash = (decimal)numberProvider.GetDoubleInRange(100.00D, 10000.00D); CardAccount currentCardAccount = new CardAccount() { CardNumber = cardNumber, CardHolderId = holderId, CardPin = pin, CardCash = cash }; return(currentCardAccount); }
public void CreateCardAccountSuccessfully() { var content = Files.ReadAllText("./Fixtures/card_account_create.json"); var client = GetMockClient(content); var repo = Get <ICardAccountRepository>(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var account = new CardAccount { UserId = userId, Active = true, Card = new Card { FullName = "Batman", ExpiryMonth = "11", ExpiryYear = "2020", Number = "4111111111111111", Type = "visa", CVV = "123" } }; var createdAccount = repo.CreateCardAccount(account); client.VerifyAll(); Assert.NotNull(createdAccount); Assert.NotNull(createdAccount.Id); Assert.Equal("AUD", createdAccount.Currency); // It seems that currency is determined by country Assert.NotNull(createdAccount.CreatedAt); Assert.NotNull(createdAccount.UpdatedAt); }
public void RemoveCardAccount(CardAccount cardAccount) { using (Repositories rep = new Repositories()) { rep.CardAccounts.Remove(cardAccount); rep.SaveChanges(); } }
public static CardAccountSummary ToSummary(this CardAccount account) { return(new CardAccountSummary { CardNumber = account.CurrentCardNumber, Amount = account.CurrentAmount }); }
private void CreateTransactionHistoryReport(TransactionInfo tranInfo, CardAccount cardAccount) { automatedTellerMachineContext.TransactionsHistories.Add(new TransactionsHistory() { Ammount = tranInfo.MoneyToRetrieve, TransactionDate = DateTime.Now, CardAccount = cardAccount }); }
public void Generate() { //Console.WriteLine("Adding Categories"); //for (int i = 0; i < this.count; i++) //{ // var cardAccount = new CardAccount // { // CardNumber = this.random.GetRandomStringOfNumbers(10), // CardPin = this.random.GetRandomStringOfNumbers(4), // CardCash = this.random.GetRandomNumber(0, 1000) // }; // this.db.CardAccounts.Add(cardAccount); // if (i % 100 == 0) // { // Console.WriteLine("... 100 categories added..."); // db.SaveChanges(); // } //} //Console.WriteLine("Categories added"); //GENERATE RANDOM CARD NUMBERS // ABSTRACT var cardNumbersToBeAdded = new HashSet <string>(); while (cardNumbersToBeAdded.Count != this.Count) { cardNumbersToBeAdded.Add(this.Random.GetRandomStringOfNumbers(10)); } int index = 0; Console.WriteLine("Adding...."); foreach (var cardNumber in cardNumbersToBeAdded) { var cardAccount = new CardAccount { CardNumber = cardNumber, CardPin = this.Random.GetRandomStringOfNumbers(4), CardCash = this.Random.GetRandomNumber(0, 1000) //......... = ...... }; if (index % 100 == 0) { Console.WriteLine("."); Database.SaveChanges(); } this.Database.CardAccounts.Add(cardAccount); index++; } Console.WriteLine("Added!"); }
public bool CreateArbitraryTransaction(ArbitraryTransaction arbitraryTransaction) { try { using (Repositories rep = new Repositories()) { CardAccount card = rep.CardAccounts.GetSingle(arbitraryTransaction.CardAccountID); BankAccount acc = rep.BankAccounts.GetSingle(card.BankAccountID); BankAccount bank = null; switch (acc.CurrencyID) { case 1: bank = rep.BankAccounts.GetAll(a => a.AcountNumber == "1111111111111111").FirstOrDefault(); break; case 2: bank = rep.BankAccounts.GetAll(a => a.AcountNumber == "1111111111111112").FirstOrDefault(); break; case 3: bank = rep.BankAccounts.GetAll(a => a.AcountNumber == "1111111111111113").FirstOrDefault(); break; case 4: bank = rep.BankAccounts.GetAll(a => a.AcountNumber == "1111111111111114").FirstOrDefault(); break; } if (arbitraryTransaction.Amount > acc.Balance) { return(false); } if (card.IsLocked) { return(false); } if (card.ExpiredDate < Time.GetTime()) { return(false); } arbitraryTransaction.Date = Time.GetTime(); acc.Balance -= arbitraryTransaction.Amount; bank.Balance += arbitraryTransaction.Amount; rep.BankAccounts.Update(acc); rep.BankAccounts.Update(bank); rep.ArbitraryTransactions.Add(arbitraryTransaction); rep.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
public string CardAccountAndClientShortInfo(CardAccount cardaccount, Customer client) { return("Карт-счет номер " + cardaccount.CardNumber + ", с наименованием: " + cardaccount.Name + ".\nТип карт-счета: " + cardaccount.CardType + ".\nКарт-счет " + (cardaccount.IsLocked == true ? "заблокирован" : "не заблокирован") + ".\nДата окончания срока использования " + cardaccount.ExpiredDate + ".\nСтатус: " + cardaccount.Status.ToLower() + /////////////////////////////////////////////////////////////////////////////////////////////// "\n" + ClientInformation(client)); }
private static void InputCardPIN(CardAccount cardFound) { var cardCandidatePin = Console.ReadLine(); if (!cardFound.CardPIN.Equals(cardCandidatePin)) { throw new InvalidOperationException("--Card PIN is invalid."); } Console.WriteLine("--Valid card PIN."); Console.WriteLine("--Current card cash: " + cardFound.CardCash.ToString("F")); }
static void SaveWithdraw(CardAccount cardAccount, decimal amount, ATMContext db) { cardAccount.CardCash -= amount; db.TransactionHistory.Add(new TransactionHistory() { CardNumber = cardAccount.CardNumber, Amount = amount }); db.SaveChanges(); }
private CardAccount CreateAccount(string ownerId, double amount) { var newAccount = new CardAccount(); var cardNumber = numberGenerator.GenerateCardNumber(); newAccount.EmitCardNumber(ownerId, amount, cardNumber); applicationDbContext.Add(newAccount); applicationDbContext.SaveChanges(); return(newAccount); }
private void BtnCreateAccount_Click(object sender, RoutedEventArgs e) { var account = new CardAccount() { CardNumber = this.cardNumber.Text, CardPin = this.cardPin.Text, CardCash = decimal.Parse(this.cardAmmount.Text) }; this.data.CardAccounts.Add(account); this.data.SaveChanges(); }
private static void Withdraw(decimal amountToWithdraw, CardAccount cardFound) { if (cardFound.CardCash - amountToWithdraw < 0) { throw new ArgumentOutOfRangeException("--Not enough money to withdraw."); } cardFound.CardCash -= amountToWithdraw; Console.Clear(); Console.WriteLine("--Withdrawn: " + amountToWithdraw.ToString("F")); Console.WriteLine("--Current amount: " + cardFound.CardCash.ToString("F")); }
public CardAccount CreateCardFromCard(CardAccount card) { return(new CardAccount { CardHolderName = card.CardHolderName, Number = card.Number, Type = card.Type, SecurityCode = card.SecurityCode ?? string.Empty, Exp = card.Exp, Id = card.Id, IsVerified = card.IsVerified }); }
public CardAccountDTO(CardAccount cardAccount) { Id = cardAccount.Id; Number = cardAccount.Number; Exp = cardAccount.Exp; Pin = cardAccount.Pin; Type = cardAccount.Type; IsVerified = cardAccount.IsVerified; CardHolderName = cardAccount.CardHolderName; SecurityCode = cardAccount.SecurityCode; MyStoreId = cardAccount.MyStoreId; MyUserId = cardAccount.MyUserId; }
internal static void Main(string[] args) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<ATMContext, Configuration>()); string cardNumber = "2563145851"; string cardPin = "1235"; decimal cash = 250; CardAccount myAccout = new CardAccount(cardNumber, cardPin, cash); var db = new ATMContext(); RetrievesMoney(db); }
public string CardAccountInformation(CardAccount el, BankAccount bankAccount, Currency currency) { return ("Номер карт-счета " + el.CardNumber + ".\nНаименование валюты " + currency.ShortName + " (" + currency.Name + ")" + ".\nСредства составляют " + bankAccount.Balance + //".\nКарт-счет " + (el.IsLocked== true ? DataSource.CardStatusLocked : DataSource.CardStatusUnLocked) + ".\nДата создания " + el.CreatedDate + ".\nДата окончания срока использования " + el.ExpiredDate + ".\nСтатус " + el.Status.ToLower() + ".\nТип карт-счета - " + el.CardType + ".\n\n" ); }
public CardAccount CreateCardAccount(CardAccount cardAccount) { var request = new RestRequest("/card_accounts", Method.POST); request.AddParameter("user_id", cardAccount.UserId); request.AddParameter("full_name", cardAccount.Card.FullName); request.AddParameter("number", cardAccount.Card.Number); request.AddParameter("expiry_month", cardAccount.Card.ExpiryMonth); request.AddParameter("expiry_year", cardAccount.Card.ExpiryYear); request.AddParameter("cvv", cardAccount.Card.CVV); var response = SendRequest(Client, request); return(JsonConvert.DeserializeObject <IDictionary <string, CardAccount> >(response.Content).Values.First()); }
public JsonResult ChangeName(string cardId, string cardName) { CardAccount card = service.GetCardAccountById(Int32.Parse(cardId)); card.Name = cardName; service.UpdateCardAccount(card); ServerResponse response = new ServerResponse() { Success = true, Info = cardId, Message = cardName }; return(Json(response)); }
public JsonResult BlockCard(string cardId) { CardAccount card = service.GetCardAccountById(Int32.Parse(cardId)); card.IsLocked = true; card.Status = "Заблокирована"; service.UpdateCardAccount(card); ServerResponse response = new ServerResponse() { Success = true, Info = cardId, Message = card.Status }; return(Json(response)); }
public bool CreateTransferTransaction(TransferTransaction transferTransaction) { try { using (Repositories rep = new Repositories()) { CardAccount targetCard = rep.CardAccounts.GetSingle(transferTransaction.TargetCardAccountID); BankAccount targetAccount = rep.BankAccounts.GetSingle(targetCard.BankAccountID); CardAccount card = rep.CardAccounts.GetSingle(transferTransaction.CardAccountID); BankAccount acc = rep.BankAccounts.GetSingle(card.BankAccountID); if (targetAccount.CurrencyID != acc.CurrencyID) { return(false); } if (transferTransaction.Amount > acc.Balance) { return(false); } if (card.IsLocked) { return(false); } if (card.ExpiredDate < Time.GetTime()) { return(false); } if (targetAccount.AcountNumber == acc.AcountNumber) { return(false); } transferTransaction.Date = Time.GetTime(); acc.Balance -= transferTransaction.Amount; targetAccount.Balance += transferTransaction.Amount; rep.BankAccounts.Update(acc); rep.BankAccounts.Update(targetAccount); rep.TransferTransactions.Add(transferTransaction); rep.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
public static void WithdrawMoney(decimal amount, string cardNumber, string cardPIN) { AtmContext atmContext = new AtmContext(); using (atmContext) { TransactionScope transaction = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions() { // This isolation level locks only the current account. // The account can be read but can't be modified. // The other accounts are not locked IsolationLevel = IsolationLevel.RepeatableRead }); using (transaction) { try { CardAccount account = atmContext.CardAccounts .FirstOrDefault( c => c.CardNumber == cardNumber && c.CardPIN == cardPIN && c.CardCash >= amount); decimal oldCash = account.CardCash; decimal newCash = account.CardCash - amount; account.CardCash = newCash; atmContext.SaveChanges(); UpdateTransactionsHistory(atmContext, account, oldCash, newCash); transaction.Complete(); } catch (NullReferenceException) { Console.WriteLine("No such card exists or the cash in the card is not enough"); } } } }
public void Can_Insert_New_CardAccount() { var user = Context.Set <User>().FirstOrDefault(x => x.UserName == "terminator"); var vendor = Context.Set <CardVendor>().Find("visa"); var currency = Context.Set <Currency>().Find("USD"); var card = new Card("1232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard = new UserCard(card, user, new CardSettings(card.Id, new CardLimits())); Context.Set <UserCard>().Add(userCard); var account = new CardAccount("1234567890123", currency, user) { ExpirationDateUtc = DateTime.UtcNow.AddDays(300) }; Context.Set <CardAccount>().Add(account); Context.SaveChanges(); }
public bool CreateSSISTransaction(SSISTransaction SSISTransaction) { try { using (Repositories rep = new Repositories()) { CardAccount card = rep.CardAccounts.GetSingle(SSISTransaction.CardAccountID); BankAccount acc = rep.BankAccounts.GetSingle(card.BankAccountID); BankAccount bank = rep.BankAccounts.GetAll(a => a.AcountNumber == "1111111111111111").FirstOrDefault(); if (acc.CurrencyID != 1) { return(false); } if (SSISTransaction.Amount > acc.Balance) { return(false); } if (card.IsLocked) { return(false); } if (card.ExpiredDate < Time.GetTime()) { return(false); } SSISTransaction.Date = Time.GetTime(); acc.Balance -= SSISTransaction.Amount; bank.Balance += SSISTransaction.Amount; rep.BankAccounts.Update(acc); rep.BankAccounts.Update(bank); rep.SSISTransactions.Add(SSISTransaction); rep.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
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; }
public UserCard Create( CardAccount cardAccount, CardVendor cardVendor, User cardOwner, string cardholderFirstName, string cardholderLastName, DateTime expirationDateUtc) { Argument.NotNull(cardAccount, "cardAccount"); Argument.NotNull(cardVendor, "cardVendor"); Argument.NotNull(cardOwner, "cardOwner"); var card = _cardFactory.Create( cardVendor, cardholderFirstName, cardholderLastName, expirationDateUtc); var settings = new CardSettings(card.Id, _cardLimitsFactory.CreateDefault(cardAccount.Currency)); var userCard = new UserCard(cardAccount, card, cardOwner, settings); return(userCard); }
public CardAccount Create(Currency currency, User owner, DateTime expirationDateUtc) { Argument.NotNull(currency, "currency"); Argument.NotNull(owner, "owner"); string accountNo; while (true) { accountNo = GenerateAccountNo(); var existingAccount = _cardAccountRepository.Find(accountNo); if (existingAccount == null) { break; } } var account = new CardAccount(accountNo, currency, owner) { ExpirationDateUtc = expirationDateUtc }; return(account); }
public void InsertCardAccount(string cardNumber, string cardPIN, decimal cash) { var options = new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead, Timeout = new TimeSpan(0, 0, 0, 10) }; using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, options)) { CardAccount account = new CardAccount { CardNumber = cardNumber, CardPIN = cardPIN, CardCash = cash }; this.atmContext.CardAccounts.Add(account); this.atmContext.SaveChanges(); scope.Complete(); } }
public JsonResult UnBlockCard(string cardId) { CardAccount card = service.GetCardAccountById(Int32.Parse(cardId)); if (card.IsLocked == true) { card.IsLocked = false; card.Status = "Действительна"; } if (card.ExpiredDate < Time.GetTime()) { card.Status = "Истек срок действия"; } service.UpdateCardAccount(card); ServerResponse response = new ServerResponse() { Success = true, Info = cardId, Message = card.Status }; return(Json(response)); }
public void Can_Insert_MultipleCards_With_Account() { var user = Context.Set <User>().FirstOrDefault(x => x.UserName == "terminator"); var vendor = Context.Set <CardVendor>().Find("visa"); var currency = Context.Set <Currency>().Find("USD"); var card1 = new Card("2232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard1 = new UserCard(card1, user, new CardSettings(card1.Id, new CardLimits())); var card2 = new Card("3232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard2 = new UserCard(card2, user, new CardSettings(card2.Id, new CardLimits())); Context.Set <UserCard>().Add(userCard1); Context.Set <UserCard>().Add(userCard2); var account1 = new CardAccount("1234567891234", currency, user) { ExpirationDateUtc = DateTime.UtcNow.AddDays(300) }; account1.Cards.Add(userCard2); Context.Set <CardAccount>().Add(account1); Context.SaveChanges(); }
protected override void Seed(ATMSystem.Data.ATMSystemContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method to avoid creating duplicate seed data. E.g. string[] cardNumbers = new string[10]; string[] cardPINs = new string[10]; decimal[] cardCash = new decimal[10]; for (int card = 0; card < cardPINs.Length; card++) { CardAccount currentCard = new CardAccount(); cardNumbers[card] = CreateRandomString(10); cardPINs[card] = CreateRandomString(4); cardCash[card] = rnd.Next(500, 10000); currentCard.CardNumber = cardNumbers[card]; currentCard.CardPIN = cardPINs[card]; currentCard.CardCash = cardCash[card]; context.CardAccounts.AddOrUpdate(currentCard); } }
public static void AddCardAccount(CardAccount newAccount, ATMContext context) { context.CardAccounts.Add(newAccount); context.SaveChanges(); Console.WriteLine("Correct added!"); }