Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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");
     }
 }
Ejemplo n.º 4
0
        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)");
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public void RemoveCardAccount(CardAccount cardAccount)
 {
     using (Repositories rep = new Repositories())
     {
         rep.CardAccounts.Remove(cardAccount);
         rep.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 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
     });
 }
Ejemplo n.º 11
0
        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!");
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 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));
 }
Ejemplo n.º 14
0
        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"));
        }
Ejemplo n.º 15
0
        static void SaveWithdraw(CardAccount cardAccount, decimal amount, ATMContext db)
        {
            cardAccount.CardCash -= amount;

            db.TransactionHistory.Add(new TransactionHistory()
            {
                CardNumber = cardAccount.CardNumber, Amount = amount
            });

            db.SaveChanges();
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
0
        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;
 }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
 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());
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
        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));
        }
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
0
        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");
                    }
                }
            }
        }
Ejemplo n.º 28
0
        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();
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
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.º 31
0
        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);
        }
Ejemplo n.º 32
0
        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);
        }
Ejemplo n.º 33
0
        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();
            }
        }
Ejemplo n.º 34
0
        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));
        }
Ejemplo n.º 35
0
        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();
        }
Ejemplo n.º 36
0
        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);
            }
        }
Ejemplo n.º 37
0
 public static void AddCardAccount(CardAccount newAccount, ATMContext context)
 {
     context.CardAccounts.Add(newAccount);
     context.SaveChanges();
     Console.WriteLine("Correct added!");
 }