private static void DepositMoney(int userId, decimal amount, BillsPaymentSystemContext context) { decimal startAmount = amount; if (!context.Users.Any(x => x.UserId == userId)) { throw new ArgumentException($"User with id {userId} not found!"); } var user = context.Users .Where(x => x.UserId == userId) .Select(x => new { Name = $"{x.FirstName} {x.LastName}", BankAccounts = x.PaymentMethods .OrderBy(i => i.BankAccountId) .Where(ba => ba.Type == PaymentMethodType.BankAccount) .Select(ba => ba.BankAccount).ToList(), CreditCards = x.PaymentMethods .OrderBy(i => i.CreditCardId) .Where(y => y.Type == PaymentMethodType.CreditCard) .Select(cc => cc.CreditCard).ToList() }).FirstOrDefault(); bool moneyAreDeposited = false; if (user.BankAccounts.Any() || user.CreditCards.Any()) { foreach (var acc in user.BankAccounts) { var currAccount = context.BankAccounts.Find(acc.BankAccountId); currAccount.Deposit(amount); moneyAreDeposited = true; context.SaveChanges(); return; } foreach (var card in user.CreditCards) { var currCard = context.CreditCards.Find(card.CreditCardId); if (currCard.MoneyOwed >= amount) { currCard.MoneyOwed -= amount; currCard.Deposit(amount); moneyAreDeposited = true; } else if (currCard.MoneyOwed > 0) { amount -= currCard.MoneyOwed; currCard.Deposit(currCard.MoneyOwed); } if (moneyAreDeposited) { context.SaveChanges(); return; } } if (!moneyAreDeposited) { context.SaveChanges(); Console.WriteLine($"{startAmount - amount:F2} were successfully deposited!"); Console.WriteLine($"Please provide valid Bank Account or Credit Card for the rest {amount:F2}"); } } else { throw new InvalidOperationException("The user does not have any bank account or credit card!"); } }
static void Seed(BillsPaymentSystemContext context) { var users = new[] { new User { FirstName = "Pesho", LastName = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Gosho", LastName = "Petrov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Stamat", LastName = "Todorov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Toshko", LastName = "Vladimirov", Email = "*****@*****.**", Password = "******" } }; context.Users.AddRange(users); var creditCards = new[] { new CreditCard(new DateTime(2018, 6, 20), 15000.00m, 1500.00m), new CreditCard(new DateTime(2018, 6, 25), 20000m, 1800m), new CreditCard(new DateTime(2019, 7, 4), 15000m, 14000m), new CreditCard(new DateTime(2019, 2, 5), 16000m, 4500m) }; context.CreditCards.AddRange(creditCards); var bankAccounts = new[] { new BankAccount(2455m, "SG Expresbank", "TGBHJKL"), new BankAccount(12000m, "Investbank", "TBGINKFL"), new BankAccount(14000m, "DSK", "TBGDSK"), new BankAccount(8500m, "Raiffensen bank", "TBGFRF") }; context.BankAccounts.AddRange(bankAccounts); var paymentMethods = new[] { new PaymentMethod { User = users[0], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[0] }, new PaymentMethod { User = users[0], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[1] }, new PaymentMethod { User = users[0], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[0] }, new PaymentMethod { User = users[1], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[1] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[2] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[2] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[3] }, new PaymentMethod { User = users[3], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[3] } }; context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); }
public static void Seed(BillsPaymentSystemContext db) { using (db) { var user = new User { FirstName = "Guy", LastName = "Gilbert", Email = "*****@*****.**", Password = "******" }; var card = new CreditCard { ExpirationDate = new DateTime(2020, 03, 1), Limit = 800m, MoneyOwed = 100m }; var bankAccounts = new[] { new BankAccount { Balance = 2000m, BankName = "Unicredit Bulbank", SwiftCode = "UNCRBGSF" }, new BankAccount { Balance = 1000m, BankName = "First Investment Bank", SwiftCode = "FINVBGSF" } } .ToList(); var paymentMethods = new[] { new PaymentMethod { User = user, BankAccount = bankAccounts[0], Type = PaymentMethodType.BankAccount }, new PaymentMethod { User = user, BankAccount = bankAccounts[1], Type = PaymentMethodType.BankAccount }, new PaymentMethod { User = user, CreditCard = card, Type = PaymentMethodType.CreditCard } } .ToList(); db.Users.Add(user); db.CreditCards.Add(card); db.BankAccounts.AddRange(bankAccounts); db.PaymentMethods.AddRange(paymentMethods); db.SaveChanges(); } }
static void Seed(BillsPaymentSystemContext context) { var users = new[] { new User { FirstName = "Aleko", LastName = "Todorov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Alisia", LastName = "Ivanova", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Neli", LastName = "Petkova", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Vladi", LastName = "Nikolav", Email = "*****@*****.**", Password = "******" } }; context.Users.AddRange(users); var creditCards = new[] { new CreditCard { Limit = 24000.00m, MoneyOwed = 1100.00m, ExpirationDate = new DateTime(2019, 2, 2), }, new CreditCard { Limit = 11000.00m, MoneyOwed = 3500.00m, ExpirationDate = new DateTime(2019, 8, 11), }, new CreditCard { Limit = 55000.00m, MoneyOwed = 200.00m, ExpirationDate = new DateTime(2018, 5, 19), }, new CreditCard { Limit = 15000.00m, MoneyOwed = 1500.00m, ExpirationDate = new DateTime(2020, 6, 10), }, }; context.CreditCards.AddRange(creditCards); var bankAccounts = new[] { new BankAccount { Balance = 9435m, BankName = "Investbank", SwiftCode = "TGBHJKL" }, new BankAccount { Balance = 7000m, BankName = "Expresbank", SwiftCode = "FRJRJWS" }, new BankAccount { Balance = 5466m, BankName = "Raiffensen", SwiftCode = "FMJEJE" }, new BankAccount { Balance = 9461m, BankName = "DSK", SwiftCode = "FKJJDSWW" } }; context.BankAccounts.AddRange(bankAccounts); var paymentMethods = new[] { new PaymentMethod { User = users[1], Type = PaymentType.BankAccount, BankAccount = bankAccounts[0] }, new PaymentMethod { User = users[2], Type = PaymentType.BankAccount, BankAccount = bankAccounts[1] }, new PaymentMethod { User = users[3], Type = PaymentType.CreditCard, CreditCard = creditCards[3] }, new PaymentMethod { User = users[0], Type = PaymentType.CreditCard, CreditCard = creditCards[1] }, new PaymentMethod { User = users[1], Type = PaymentType.BankAccount, BankAccount = bankAccounts[2] }, new PaymentMethod { User = users[2], Type = PaymentType.CreditCard, CreditCard = creditCards[2] }, new PaymentMethod { User = users[3], Type = PaymentType.CreditCard, CreditCard = creditCards[3] }, new PaymentMethod { User = users[0], Type = PaymentType.BankAccount, BankAccount = bankAccounts[1] } }; context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); }
private static void PayBills(int userId, decimal amount, BillsPaymentSystemContext context) { decimal allАvailableMoneyOfUser = 0m; var bankAccounts = context .BankAccounts.Join(context.PaymentMethods, (ba => ba.BankAccountId), (p => p.BankAccountId), (ba, p) => new { UserId = p.UserId, BankAccountId = ba.BankAccountId, Balance = ba.Balance }) .Where(ba => ba.UserId == userId) .ToList(); var creditCards = context .CreditCards.Join(context.PaymentMethods, (c => c.CreditCardId), (p => p.CreditCardId), (c, p) => new { UserId = p.UserId, CreditCardId = c.CreditCardId, LimitLeft = c.LimitLeft }) .Where(c => c.UserId == userId) .ToList(); allАvailableMoneyOfUser += bankAccounts.Sum(b => b.Balance); allАvailableMoneyOfUser += creditCards.Sum(c => c.LimitLeft); if (allАvailableMoneyOfUser < amount) { throw new InvalidOperationException("Insufficient funds!"); } bool isPayBills = false; foreach (var bankAccount in bankAccounts.OrderBy(b => b.BankAccountId)) { var currentAccount = context.BankAccounts.Find(bankAccount.BankAccountId); if (amount <= currentAccount.Balance) { currentAccount.Withdraw(amount); isPayBills = true; } else { amount -= currentAccount.Balance; currentAccount.Withdraw(currentAccount.Balance); } if (isPayBills) { context.SaveChanges(); return; } } foreach (var creditCard in creditCards.OrderBy(c => c.CreditCardId)) { var currentCreditCard = context.CreditCards.Find(creditCard.CreditCardId); if (amount <= currentCreditCard.LimitLeft) { currentCreditCard.Withdraw(amount); isPayBills = true; } else { amount -= currentCreditCard.LimitLeft; currentCreditCard.Withdraw(currentCreditCard.LimitLeft); } if (isPayBills) { context.SaveChanges(); return; } } }
private static void PayBills(int userId, decimal billsAmount, BillsPaymentSystemContext context) { var userBankAccounts = context.PaymentMethods .Include(pm => pm.BankAccount) .Where(u => u.UserId == userId && u.Type == PaymentMethodType.BankAccount) .Select(u => new { u.UserId, BankAccountId = u.BankAccountId, Balance = u.BankAccount.Balance, }) .ToList(); var userCreditCards = context.PaymentMethods .Include(b => b.CreditCard) .Where(u => u.UserId == userId && u.Type == PaymentMethodType.CreditCard) .Select(u => new { u.UserId, u.CreditCardId, LimitLeft = u.CreditCard.LimitLeft }).ToList(); if (userBankAccounts.Count == 0 && userCreditCards.Count == 0) { throw new ArgumentException($"No user with id {userId}"); } decimal allBankAccountBalance = userBankAccounts.Sum(a => a.Balance); decimal allCreditCardsBalance = userCreditCards.Sum(a => a.LimitLeft); decimal allBalance = allBankAccountBalance + allCreditCardsBalance; if (billsAmount > allBalance) { throw new ArgumentException("Insufficient funds!"); } bool isBillsPaid = false; foreach (var bankAcc in userBankAccounts.OrderBy(x => x.BankAccountId)) { var currentAccount = context.BankAccounts.FirstOrDefault(ba => ba.BankAccountId == bankAcc.BankAccountId); if (currentAccount.Balance > billsAmount) { currentAccount.Withdraw(billsAmount); isBillsPaid = true; } else { billsAmount = billsAmount - currentAccount.Balance; currentAccount.Withdraw(currentAccount.Balance); } if (isBillsPaid) { context.SaveChanges(); return; } } if (!isBillsPaid) { foreach (var cc in userCreditCards.OrderBy(a => a.CreditCardId)) { var currentCard = context.CreditCards.FirstOrDefault(c => c.CreditCardId == cc.CreditCardId); if (currentCard.LimitLeft > billsAmount) { currentCard.Withdraw(billsAmount); isBillsPaid = true; } else { billsAmount = billsAmount - currentCard.LimitLeft; currentCard.Withdraw(currentCard.LimitLeft); } if (isBillsPaid) { context.SaveChanges(); return; } } } }
private static void Seed(BillsPaymentSystemContext db) { using (db) { var user = new User() { FirstName = "Ivan", LastName = "Petrov", Email = "*****@*****.**", Password = "******" }; var creditCards = new CreditCard[] { new CreditCard() { ExpirationDate = DateTime.ParseExact("20.05.2020", "dd.MM.yyyy", null), Limit = 1000m, MoneyOwed = 5m }, new CreditCard() { ExpirationDate = DateTime.ParseExact("20.05.2020", "dd.MM.yyyy", null), Limit = 2500m, MoneyOwed = 300m } }; var bankAccount = new BankAccount() { Balance = 3000m, BankName = "Swiss Bank", SwiftCode = "SSWSBKJS" }; var paymentMethods = new PaymentMethod[] { new PaymentMethod() { User = user, CreditCard = creditCards[0], Type = PaymentMethodType.CreditCard }, new PaymentMethod() { User = user, CreditCard = creditCards[1], Type = PaymentMethodType.CreditCard }, new PaymentMethod() { User = user, BankAccount = bankAccount, Type = PaymentMethodType.BankAccount } }; db.Users.Add(user); db.CreditCards.AddRange(creditCards); db.BankAccounts.Add(bankAccount); db.PaymentMethods.AddRange(paymentMethods); db.SaveChanges(); } }
private static void PayBills(int userId, decimal amount) { using (var context = new BillsPaymentSystemContext()) { var userMoneyAmounts = context.Users .Where(u => u.UserId == userId) .Select(u => new decimal[] { u.PaymentMethods .Where(pm => pm.BankAccountId != null) .Sum(pm => pm.BankAccount.Balance), u.PaymentMethods .Where(pm => pm.CreditCardId != null) .Sum(pm => pm.CreditCard.LimitLeft) }).ToArray(); BankAccount[] bankAccounts = context.PaymentMethods.Where(pm => pm.UserId == userId && pm.BankAccount != null).Select(u => u.BankAccount).OrderBy(a => a.BankAccountId).ToArray(); CreditCard[] creditCards = context.PaymentMethods.Where(pm => pm.UserId == userId && pm.CreditCard != null).Select(pm => pm.CreditCard).OrderBy(cc => cc.CreditCardId).ToArray(); decimal sumBankAccounts = userMoneyAmounts[0][0]; decimal sumCreditCards = userMoneyAmounts[0][1]; if (sumBankAccounts + sumCreditCards >= amount) { foreach (var bankAccount in bankAccounts) { if (bankAccount.Balance > amount) { bankAccount.Withdraw(amount); amount = 0; } else { amount -= bankAccount.Balance; bankAccount.Withdraw(bankAccount.Balance); } } foreach (var creditCard in creditCards) { if (creditCard.LimitLeft >= amount) { creditCard.Withdraw(amount); amount = 0; } else { amount -= creditCard.LimitLeft; creditCard.Withdraw(creditCard.LimitLeft); } } } else { Console.WriteLine("Insufficient funds!"); } context.SaveChanges(); } }
private static void PayBills(int userId, decimal amount) { using (var db = new BillsPaymentSystemContext()) { var toPayFromAccounts = db.BankAccounts .Where(ba => ba.PaymentMethod.UserId == userId) .OrderBy(ba => ba.BankAccountId) .ToList(); var toPayFromCredit = db.CreditCards .Where(cc => cc.PaymentMethod.UserId == userId) .OrderBy(cc => cc.CreditCardId) .ToList(); var totalBalance = toPayFromAccounts .Sum(b => b.Balance) + toPayFromCredit .Sum(cc => cc.LimitLeft); if (totalBalance < amount) { throw new ArgumentOutOfRangeException("Insufficient funds!"); } bool wereBillsPaied = false; foreach (var bankAccount in toPayFromAccounts) { if (wereBillsPaied) { break; } if (bankAccount.Balance >= amount) { bankAccount.Withdraw(amount); amount = 0; wereBillsPaied = true; } else { amount -= bankAccount.Balance; bankAccount.Withdraw(bankAccount.Balance); } } foreach (var creditCard in toPayFromCredit) { if (wereBillsPaied) { break; } if (creditCard.LimitLeft >= amount) { creditCard.Withdraw(amount); amount = 0; wereBillsPaied = true; } else { amount -= creditCard.LimitLeft; creditCard.Withdraw(creditCard.LimitLeft); } } db.SaveChanges(); } }
internal string Withdraw(int userId, decimal amount) { decimal totalBalanceBankAccount = 0; decimal totalBalanceCreditCard = 0; string result = null; var paymentMethods = context.PaymentMethods .Where(pm => pm.UserId == userId) .Include("BankAccount") .Include("CreditCard") .ToList(); foreach (var paymentMethod in paymentMethods) { if (paymentMethod.Type == PaymentType.BankAccount) { decimal balanceBank = paymentMethod.BankAccount.Balance; if (balanceBank < amount) { continue; } else { paymentMethod.BankAccount.Balance -= amount; context.SaveChanges(); totalBalanceBankAccount = paymentMethod.BankAccount.Balance; result = $"BankAccount -> {totalBalanceBankAccount}"; break; } } else if (paymentMethod.Type == PaymentType.CreditCard) { var balanceCredit = paymentMethod.CreditCard.MoneyOwed; var limitLeft = paymentMethod.CreditCard.LimitLeft; if (balanceCredit < amount && limitLeft < amount) { continue; } else { paymentMethod.CreditCard.MoneyOwed -= amount; context.SaveChanges(); totalBalanceCreditCard = paymentMethod.CreditCard.MoneyOwed; result = $"BankAccount -> {totalBalanceCreditCard}"; break; } } } if (result == null) { return("Insufficient funds!"); } return(result); }
private static void Seed(BillsPaymentSystemContext db) { using ( db) { var user = new User() { FirstName = "Pesho", LastName = "Stamatov", Email = "*****@*****.**", Password = "******" }; var credCards = new CreditCard[] { new CreditCard() { ExpirationDate = new DateTime(2018, 6, 28), Limit = 1000m, MoneyOwned = 5m }, new CreditCard() { ExpirationDate = new DateTime(2012, 4, 12), Limit = 400m, MoneyOwned = 200m } }; var bankAccount = new BankAccount() { Balance = 1230m, SwiftCode = "FINVBFSF", BankName = "Swiss Band" }; var paymentMethods = new PaymentMethod[] { new PaymentMethod() { User = user, CreditCard = credCards[0], Type = PaymentMethodType.CreditCard }, new PaymentMethod() { User = user, CreditCard = credCards[1], Type = PaymentMethodType.CreditCard }, new PaymentMethod() { User = user, BankAccount = bankAccount, Type = PaymentMethodType.BankAccount }, }; db.Users.Add(user); db.CreditCards.AddRange(credCards); db.BankAccounts.Add(bankAccount); db.PaymentMethods.AddRange(paymentMethods); db.SaveChanges(); } }
internal static void SeedDb(BillsPaymentSystemContext currentDb) { using (currentDb) { User[] users = new User[] { new User() { FirstName = "Ivanov", LastName = "Petrov", Email = "*****@*****.**", Password = "******" }, new User() { FirstName = "Tanya", LastName = "Fikova", Email = "*****@*****.**", Password = "******" } }; CultureInfo provider = CultureInfo.InvariantCulture; CreditCard[] creditCards = { new CreditCard() { ExpirationDate = DateTime.ParseExact("21.06.2019", "dd.MM.yyyy", provider), Limit = 2000m, MoneyOwed = 50m, }, new CreditCard() { ExpirationDate = DateTime.ParseExact("22.07.2020", "dd.MM.yyyy", provider), Limit = 3000m, MoneyOwed = 500m, }, new CreditCard() { ExpirationDate = DateTime.ParseExact("23.08.2018", "dd.MM.yyyy", provider), Limit = 6000m, MoneyOwed = 3.1m, } }; BankAccount[] bankAccounts = { new BankAccount() { Balance = 1400m, BankName = "BankOfSvalbard", SWIFTCode = "SVLBRDMNY" }, new BankAccount() { Balance = 1565m, BankName = "BankOfWrangelIsland", SWIFTCode = "WRNGLGLD" } }; PaymentMethod[] paymentMethods = new PaymentMethod[] { new PaymentMethod { User = users[0], CreditCard = creditCards[0], Type = AccountType.CreditCard }, new PaymentMethod { User = users[0], CreditCard = creditCards[1], Type = AccountType.CreditCard }, new PaymentMethod { User = users[0], BankAccount = bankAccounts[0], Type = AccountType.BankAccount }, // This causes an exception, as it should //new PaymentMethod //{ // User = users[0], // BankAccount = bankAccounts[0], // CreditCard = creditCards[2], // Type = AccountType.BankAccount //}, }; currentDb.Users.AddRange(users); currentDb.CreditCards.AddRange(creditCards); currentDb.BankAccounts.AddRange(bankAccounts); currentDb.PaymentMethods.AddRange(paymentMethods); currentDb.SaveChanges(); } }
public static void SeedDb(BillsPaymentSystemContext db) { var firstAcc = new BankAccount { BankName = "First Investment Bank", SwiftCode = "FINVBGSF", }; firstAcc.Deposit(1000); var secondAcc = new BankAccount { BankName = "Unicredit Bulbank", SwiftCode = "UNCRBGSF" }; secondAcc.Deposit(1000); var firstCreditCard = new CreditCard { Limit = 1000, ExpirationDate = new DateTime(2020, 01, 01) }; firstCreditCard.Withdraw(200); var secondCreditCard = new CreditCard { Limit = 2000, ExpirationDate = new DateTime(2020, 01, 01) }; secondCreditCard.Withdraw(500); var firstUser = new User { FirstName = "Mickey", LastName = "Mouse", Email = "*****@*****.**", Password = "******" }; var secondUser = new User { FirstName = "Donald", LastName = "Duck", Email = "*****@*****.**", Password = "******" }; var firstPayment = new PaymentMethod { BankAccount = firstAcc, User = firstUser, Type = PaymentType.BankAccount }; var secondPayment = new PaymentMethod { BankAccount = secondAcc, User = firstUser, Type = PaymentType.BankAccount }; var thirdPayment = new PaymentMethod { CreditCard = firstCreditCard, User = firstUser, Type = PaymentType.CreditCard }; var fourthPayment = new PaymentMethod { CreditCard = secondCreditCard, User = firstUser, Type = PaymentType.CreditCard }; db.Users.AddRange(firstUser, secondUser); db.CreditCards.AddRange(firstCreditCard, secondCreditCard); db.BankAccounts.AddRange(firstAcc, secondAcc); db.PaymentMethods.AddRange(firstPayment, secondPayment, thirdPayment, fourthPayment); db.SaveChanges(); }
static void PayBills() { using (var context = new BillsPaymentSystemContext()) { try { Console.WriteLine("Bills Payment"); Console.Write("Enter user ID: "); int userId = int.Parse(Console.ReadLine()); Console.Write("Enter amount: "); decimal amount = decimal.Parse(Console.ReadLine()); var accounts = context.PaymentMethods .Include(pm => pm.BankAccount) .Where(pm => pm.UserId == userId && pm.Type == PaymentMethodType.BankAccount) .Select(pm => pm.BankAccount) .ToList(); var cards = context.PaymentMethods .Include(pm => pm.CreditCard) .Where(pm => pm.UserId == userId && pm.Type == PaymentMethodType.CreditCard) .Select(pm => pm.CreditCard) .ToList(); var moneyAvailable = accounts.Select(ba => ba.Balance).Sum() + cards.Select(cc => cc.LimitLeft).Sum(); if (moneyAvailable < amount) { throw new Exception("Insufficient Funds"); return; } foreach (var account in accounts) { if (amount == 0 || account.Balance == 0) { continue; } decimal moneyInAccount = account.Balance; if (moneyInAccount < amount) { account.Withdraw(moneyInAccount); amount -= moneyInAccount; } else { account.Withdraw(amount); amount -= amount; } } foreach (var creditCard in cards) { if (amount == 0 || creditCard.LimitLeft == 0) { continue; } decimal limitLeft = creditCard.LimitLeft; if (limitLeft < amount) { creditCard.Withdraw(limitLeft); amount -= limitLeft; } else { creditCard.Withdraw(amount); amount -= amount; } } context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
private static void SeedDatabase() { PaymentMethod[] paymentMethods = { new PaymentMethod { User = new User { FirstName = "Ivan", LastName = "Gogov", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.BankAccount, BankAccount = new BankAccount { Balance = 120, BankName = "Random Bank", SwiftCode = "RDBank123" }, CreditCard = null }, new PaymentMethod { User = new User { FirstName = "Tosho", LastName = "Toshev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.BankAccount, BankAccount = new BankAccount { Balance = 111110, BankName = "Random Bank", SwiftCode = "RDBank124" }, CreditCard = null }, new PaymentMethod { User = new User { FirstName = "Petur", LastName = "Sevliev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.BankAccount, BankAccount = new BankAccount { Balance = 12, BankName = "Shitty Bank", SwiftCode = "ShittyBank123" }, CreditCard = null }, new PaymentMethod { User = new User { FirstName = "Vasil", LastName = "Mendeleev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.BankAccount, BankAccount = new BankAccount { Balance = 5, BankName = "Shitty Bank", SwiftCode = "ShittyBank124" }, CreditCard = null }, new PaymentMethod { User = new User { FirstName = "Misho", LastName = "Zvezdev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.BankAccount, BankAccount = new BankAccount { Balance = 50, BankName = "Shitty Bank", SwiftCode = "ShittyBank125" }, CreditCard = null }, new PaymentMethod { User = new User { FirstName = "Pencho", LastName = "Penchev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.CreditCard, BankAccount = null, CreditCard = new CreditCard { Limit = 100000, MoneyOwed = 100, ExpirationDate = new DateTime(2040, 11, 1) } }, new PaymentMethod { User = new User { FirstName = "Zdravko", LastName = "Jelev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.CreditCard, BankAccount = null, CreditCard = new CreditCard { Limit = 1200, MoneyOwed = 200, ExpirationDate = new DateTime(2042, 4, 15) } }, new PaymentMethod { User = new User { FirstName = "Ivan", LastName = "Gogov", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.CreditCard, BankAccount = null, CreditCard = new CreditCard { Limit = 10, MoneyOwed = 2, ExpirationDate = new DateTime(2040, 12, 1) } }, new PaymentMethod { User = new User { FirstName = "Sasho", LastName = "Uchev", Email = "*****@*****.**", Password = "******" }, PaymentType = PaymentType.CreditCard, BankAccount = null, CreditCard = new CreditCard { Limit = 10000, MoneyOwed = 9990, ExpirationDate = new DateTime(2040, 2, 20) } } }; using (var context = new BillsPaymentSystemContext()) { context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); } }
public static void Main(string[] args) { var userId = int.Parse(Console.ReadLine()); var amount = decimal.Parse(Console.ReadLine()); string command = Console.ReadLine(); using (var db = new BillsPaymentSystemContext()) { RestartDb(db); try { var user = db.Users .Where(u => u.UserId == userId) .Select(u => new { Name = $"{u.FirstName} {u.LastName}", CreditCards = u.PaymentMethods .Where(pm => pm.Type == PaymentMethodType.CreditCard) .Select(pm => pm.CreditCard).ToList(), BankAccounts = u.PaymentMethods .Where(pm => pm.Type == PaymentMethodType.BankAccount) .Select(pm => pm.BankAccount).ToList(), }) .FirstOrDefault(); Console.WriteLine($"User: {user.Name}"); var bankAccounts = user.BankAccounts; if (bankAccounts.Any()) { Console.WriteLine($"BankAccounts:"); foreach (var x in bankAccounts) { x.Balance = PayBills(amount, command); db.SaveChanges(); Console.WriteLine($@"--ID: {x.BankAccountId} ---Balance: {x.Balance} ---Bank: {x.BankName} ---SWIFT: {x.SWIFTCode}"); } } var creditCards = user.CreditCards; if (creditCards.Any()) { Console.WriteLine($"Credit Cards:"); foreach (var y in creditCards) { Console.WriteLine($@"--ID: {y.CreditCardId} ---Limit: {y.Limit:f2} ---Money Owed: {y.MoneyOwed:f2} ---Limit Left: {y.LimitLeft:f2} ---Expiration Date: {y.ExpirationDate.ToString("yyyy/MM")}"); } } } catch { Console.WriteLine($"User with id {userId} not found!"); } } }
public static void Seed(BillsPaymentSystemContext context) { var users = new[] { new User { FirstName = "Pesho", LastName = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Ivan", LastName = "Georgiev", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Maria", LastName = "Atanasova", Email = "*****@*****.**", Password = "******" } }; context.Users.AddRange(users); var bankAccounts = new[] { new BankAccount() { BankName = "Bulbank", SwiftCode = "UNCRBGSF" }, new BankAccount() { BankName = "Fibank", SwiftCode = "FINVBGSF" }, new BankAccount() { BankName = "Postbank", SwiftCode = "BPBIBGSF" } }; bankAccounts[0].Deposit(15000m); bankAccounts[1].Deposit(50000m); bankAccounts[2].Deposit(78000m); context.BankAccounts.AddRange(bankAccounts); var creditCards = new[] { new CreditCard() { Limit = 5000m, ExpirationDate = DateTime.Parse("15.12.2019") }, new CreditCard() { Limit = 2000m, ExpirationDate = DateTime.Parse("15.01.2020") }, new CreditCard() { Limit = 1000m, ExpirationDate = DateTime.Parse("31.12.2018") } }; creditCards[0].Deposit(1000m); creditCards[1].Deposit(500m); creditCards[2].Deposit(250m); context.CreditCards.AddRange(creditCards); var paymentMethods = new[] { new PaymentMethod() { UserId = users[0].UserId, Type = PaymentMethodType.BankAccount, BankAccountId = bankAccounts[0].BankAccountId }, new PaymentMethod() { UserId = users[0].UserId, Type = PaymentMethodType.BankAccount, BankAccountId = bankAccounts[2].BankAccountId }, new PaymentMethod() { UserId = users[1].UserId, Type = PaymentMethodType.CreditCard, CreditCardId = creditCards[1].CreditCardId }, new PaymentMethod() { UserId = users[2].UserId, Type = PaymentMethodType.BankAccount, BankAccountId = bankAccounts[1].BankAccountId }, new PaymentMethod() { UserId = users[2].UserId, Type = PaymentMethodType.CreditCard, CreditCardId = creditCards[2].CreditCardId }, new PaymentMethod() { UserId = users[2].UserId, Type = PaymentMethodType.CreditCard, CreditCardId = creditCards[0].CreditCardId } }; context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); }
private static void Seed(BillsPaymentSystemContext context) { using (context) { var user = new User() { FirstName = "Guy", LastName = "Gilbert", Email = "*****@*****.**", Password = "******" }; var creditCard = new CreditCard() { ExpirationDate = DateTime.ParseExact("03.03.2020", "dd.MM.yyyy", null), Limit = 800, MoneyOwed = 100 }; var bankAccounts = new[] { new BankAccount() { Balance = 2000, BankName = "Unicredit Bulbank", SwiftCode = "UNCRBGSF" }, new BankAccount() { Balance = 1000, BankName = "First Investment Bank", SwiftCode = "FINVBGSF" } }; var paymentMethods = new PaymentMethod[] { new PaymentMethod() { User = user, CreditCard = creditCard, Type = PaymentMethodType.CreditCard }, new PaymentMethod() { User = user, BankAccount = bankAccounts[0], Type = PaymentMethodType.BankAccount }, new PaymentMethod() { User = user, BankAccount = bankAccounts[1], Type = PaymentMethodType.BankAccount } }; context.Users.Add(user); context.CreditCards.Add(creditCard); context.BankAccounts.AddRange(bankAccounts); context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); } }
public string Execute(string[] args) { int userId = int.Parse(args[0]); var amount = decimal.Parse(args[1]); var user = context .Users.Select(users => new { users.UserId, BankAccounts = users.PaymentMethods .Where(x => x.Type == PaymentType.BankAccount) .Select(x => x.BankAccount) .ToArray(), CreditCards = users.PaymentMethods .Where(x => x.Type == PaymentType.CreditCard) .Select(x => x.CreditCard) .ToArray() }) .FirstOrDefault(x => x.UserId == userId); if (user == null) { throw new ArgumentNullException($"User with id {userId} not found!"); } var bankAccountsTotal = user.BankAccounts.Sum(x => x.Balance); var creditCardTotal = user.CreditCards.Sum(x => x.LimitLeft); var totalAmount = bankAccountsTotal + creditCardTotal; if (totalAmount >= amount) { var bankAccounts = user.BankAccounts.OrderBy(s => s.BankAccountId); foreach (var bankAccount in bankAccounts) { if (bankAccount.Balance >= amount) { bankAccount.Withdraw(amount); amount = 0; } else { amount -= bankAccount.Balance; bankAccount.Withdraw(bankAccount.Balance); } if (amount == 0) { break; } } var creditCards = user.CreditCards.OrderBy(x => x.CreditCardId); foreach (var creditCard in creditCards) { if (creditCard.LimitLeft >= amount) { creditCard.Withdraw(amount); amount = 0; } else { amount -= creditCard.LimitLeft; creditCard.Withdraw(creditCard.LimitLeft); } if (amount == 0) { break; } } } context.SaveChanges(); return("Bills are successfully payed. Thanks and have a nice day!"); }
private static void Seed(BillsPaymentSystemContext context) { var users = new List <User> { new User { FirstName = "Pasho", LastName = "Petkov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Mery", LastName = "Christmas", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Ivan", LastName = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Nikola", LastName = "Savov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Katq", LastName = "Minkova", Email = "*****@*****.**", Password = "******" }, }; context.Users.AddRange(users); var creditCards = new List <CreditCard> { new CreditCard { Limit = 1000, MoneyOwed = 50, ExpirationDate = DateTime.Parse("12/2018") }, new CreditCard { Limit = 10000, MoneyOwed = 2000, ExpirationDate = DateTime.Parse("10/2025") }, new CreditCard { Limit = 500, MoneyOwed = 25.40m, ExpirationDate = DateTime.Parse("07/2020") }, new CreditCard { Limit = 1500, MoneyOwed = 30, ExpirationDate = DateTime.Parse("12/2017") }, new CreditCard { Limit = 2500, MoneyOwed = 1500, ExpirationDate = DateTime.Parse("10/2018") }, new CreditCard { Limit = 5000, MoneyOwed = 3125, ExpirationDate = DateTime.Parse("05/2022") }, new CreditCard { Limit = 3000, MoneyOwed = 100, ExpirationDate = DateTime.Parse("12/2021") }, }; context.CreditCards.AddRange(creditCards); var bankAccounts = new List <BankAccount> { new BankAccount { Balance = 2500, BankName = "UniCredit", SWIFTCode = "1234" }, new BankAccount { Balance = 50, BankName = "RaifaizenBank", SWIFTCode = "0000" }, new BankAccount { Balance = 10500, BankName = "ExpressBank", SWIFTCode = "4567" }, new BankAccount { Balance = 500, BankName = "UniCredit", SWIFTCode = "5555" }, new BankAccount { Balance = 756.55m, BankName = "ExpressBank", SWIFTCode = "7896" }, new BankAccount { Balance = 1253, BankName = "DSK", SWIFTCode = "2314" }, new BankAccount { Balance = 900, BankName = "DSK", SWIFTCode = "4567" } }; context.BankAccounts.AddRange(bankAccounts); var payments = new List <PaymentMethod> { new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[0], BankAccount = bankAccounts[0] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[1], BankAccount = bankAccounts[6] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[2], BankAccount = bankAccounts[5] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[3], BankAccount = bankAccounts[4] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[4], BankAccount = bankAccounts[3] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[4], BankAccount = bankAccounts[2] }, new PaymentMethod { Type = PaymentMethodType.BankAccount, User = users[3], BankAccount = bankAccounts[1] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[0], CreditCard = creditCards[4] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[1], CreditCard = creditCards[3] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[2], CreditCard = creditCards[2] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[4], CreditCard = creditCards[1] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[4], CreditCard = creditCards[0] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[2], CreditCard = creditCards[5] }, new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[2], CreditCard = creditCards[6] }, //proverka za unikalen userId,creditcardId,bankaAccountId //new PaymentMethod { Type = PaymentMethodType.CreditCard, User = users[0], CreditCard = creditCards[4]} }; context.PaymentMethods.AddRange(payments); context.SaveChanges(); }
private static void PayBills(int userId, decimal amount, BillsPaymentSystemContext context) { if (!context.Users.Any(x => x.UserId == userId)) { throw new ArgumentException($"User with id {userId} not found!"); } var user = context.Users .Where(x => x.UserId == userId) .Select(x => new { Name = $"{x.FirstName} {x.LastName}", BankAccounts = x.PaymentMethods .OrderBy(i => i.BankAccountId) .Where(ba => ba.Type == PaymentMethodType.BankAccount) .Select(ba => ba.BankAccount).ToList(), CreditCards = x.PaymentMethods .OrderBy(i => i.CreditCardId) .Where(y => y.Type == PaymentMethodType.CreditCard) .Select(cc => cc.CreditCard).ToList() }).FirstOrDefault(); decimal bankAccBalance = 0.0m; foreach (var acc in user.BankAccounts) { decimal currBal = acc.Balance; bankAccBalance += currBal; } decimal cardBalance = 0.0m; foreach (var card in user.CreditCards) { decimal currLeftLimit = card.LimitLeft; cardBalance += currLeftLimit; } decimal totalBalance = bankAccBalance + cardBalance; if (totalBalance < amount) { throw new InvalidOperationException("Insufficient funds!"); } bool billsArePaid = false; foreach (var acc in user.BankAccounts) { var currAccount = context.BankAccounts.Find(acc.BankAccountId); if (amount <= currAccount.Balance) { currAccount.Withdraw(amount); billsArePaid = true; } else { amount -= currAccount.Balance; currAccount.Withdraw(currAccount.Balance); } if (billsArePaid) { context.SaveChanges(); return; } } foreach (var card in user.CreditCards) { var currCard = context.CreditCards.Find(card.CreditCardId); if (amount <= currCard.LimitLeft) { currCard.Withdraw(amount); billsArePaid = true; } else { amount -= currCard.LimitLeft; currCard.Withdraw(currCard.LimitLeft); } if (billsArePaid) { context.SaveChanges(); return; } } }
private static void PayBill(string id, string amount) { int userId = 0; bool isInt = int.TryParse(id, out userId); if (!isInt) { throw new InvalidOperationException("User ID entered is invalid"); } decimal billAmount = 0m; bool isAmountValid = decimal.TryParse(amount, out billAmount); if (!isAmountValid) { throw new InvalidOperationException("Invalid bill amount provided"); } if (billAmount < 0) { throw new InvalidOperationException("Bill amount cannot be negative"); } using (var db = new BillsPaymentSystemContext()) { var user = db.Users .Where(u => u.UserId == userId) .Include(u => u.PaymentMethods) .ThenInclude(pm => pm.CreditCard) .Include(u => u.PaymentMethods) .ThenInclude(pm => pm.BankAccount) .FirstOrDefault(); if (user == null) { throw new InvalidOperationException($"User with ID { userId } not found!"); } var bankAccFunds = user.PaymentMethods .Where(pm => pm.Type == PaymentType.BankAccount) .Sum(pm => pm.BankAccount.Balance); var creditCardFunds = user.PaymentMethods .Where(pm => pm.Type == PaymentType.CreditCard) .Sum(pm => pm.CreditCard.LimitLeft); var totalFundsAvailable = bankAccFunds + creditCardFunds; if (totalFundsAvailable < billAmount) { throw new InvalidOperationException("Insufficient funds"); } var bankAccounts = user.PaymentMethods .Where(pm => pm.Type == PaymentType.BankAccount) .OrderBy(pm => pm.BankAccountId) .Select(pm => pm.BankAccount) .ToList(); foreach (var ba in bankAccounts) { if (ba.Balance >= billAmount) { ba.Withdraw(billAmount); billAmount = 0; break;; } else { billAmount -= ba.Balance; ba.Withdraw(ba.Balance); } } if (billAmount > 0) { var creditCards = user.PaymentMethods .Where(pm => pm.Type == PaymentType.CreditCard) .OrderBy(pm => pm.CreditCardId) .Select(pm => pm.CreditCard) .ToList(); foreach (var cc in creditCards) { if (cc.LimitLeft >= billAmount) { cc.Withdraw(billAmount); billAmount = 0; break;; } else { billAmount -= cc.LimitLeft; cc.Withdraw(cc.LimitLeft); } } } db.SaveChanges(); Console.WriteLine("Bill successfully paid"); //TODO - actual payment } }
private static void Seed(BillsPaymentSystemContext context) { List <User> users = new List <User>() { new User { FirstName = "Tomas", LastName = "Jefferson", Password = "******", Email = "*****@*****.**" }, new User { FirstName = "Abraham", LastName = "Lincoln", Password = "******", Email = "*****@*****.**" }, new User { FirstName = "Frank", LastName = "Sinatra", Password = "******", Email = "*****@*****.**" } }; context.Users.AddRange(users); context.SaveChanges(); List <CreditCard> creditCards = new List <CreditCard>() { new CreditCard { ExpirationDate = DateTime.ParseExact("11.10.2020", "MM.dd.yyyy", null), Limit = 1000.00m, MoneyOwed = 0.0m }, new CreditCard { ExpirationDate = DateTime.ParseExact("08.21.2021", "MM.dd.yyyy", null), Limit = 1500.00m, MoneyOwed = 0.0m }, new CreditCard { ExpirationDate = DateTime.ParseExact("09.20.2022", "MM.dd.yyyy", null), Limit = 2000.00m, MoneyOwed = 0.0m }, new CreditCard { ExpirationDate = DateTime.ParseExact("03.24.2021", "MM.dd.yyyy", null), Limit = 1500.00m, MoneyOwed = 0.0m }, new CreditCard { ExpirationDate = DateTime.ParseExact("09.25.2021", "MM.dd.yyyy", null), Limit = 1500.00m, MoneyOwed = 0.0m } }; context.CreditCards.AddRange(creditCards); context.SaveChanges(); List <BankAccount> bankAccounts = new List <BankAccount>() { new BankAccount { Balance = 1250.00m, BankName = "Unicredit", SwiftCode = "UNCBANK" }, new BankAccount { Balance = 1900.00m, BankName = "Swiss Bank", SwiftCode = "SWSSBANK" }, new BankAccount { Balance = 1500.00m, BankName = "First Investment Bank", SwiftCode = "FRSTINVSTMNBANK" } }; context.BankAccounts.AddRange(bankAccounts); context.SaveChanges(); List <PaymentMethod> paymentMethods = new List <PaymentMethod>() { new PaymentMethod { User = users[0], CreditCard = creditCards[0], Type = PaymentMethodType.CreditCard, }, new PaymentMethod { User = users[0], CreditCard = creditCards[3], Type = PaymentMethodType.CreditCard, }, new PaymentMethod { User = users[1], CreditCard = creditCards[1], Type = PaymentMethodType.CreditCard, }, new PaymentMethod { User = users[2], CreditCard = creditCards[2], Type = PaymentMethodType.CreditCard, }, new PaymentMethod { User = users[0], BankAccount = bankAccounts[0], Type = PaymentMethodType.BankAccount, }, new PaymentMethod { User = users[1], BankAccount = bankAccounts[1], Type = PaymentMethodType.BankAccount, } }; context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); }
// 02. Seed Some Data private static void Seed(BillsPaymentSystemContext db) { using (db) { var user1 = new User() { FirstName = "Choko", LastName = "Boko", Email = "*****@*****.**", Password = "******" }; var creditrcards = new CreditCard[] { new CreditCard { ExpirationDate = DateTime.ParseExact("19.07.2017", "dd.mm.yyyy", CultureInfo.InvariantCulture), Limit = 4500m, MoneyOwed = 230m }, new CreditCard { ExpirationDate = DateTime.ParseExact("01.12.1989", "dd.mm.yyyy", CultureInfo.InvariantCulture), Limit = 10000m, MoneyOwed = 0m }, new CreditCard { ExpirationDate = DateTime.ParseExact("24.04.2010", "dd.mm.yyyy", CultureInfo.InvariantCulture), Limit = 500m, MoneyOwed = 50m }, }; var bankAccount = new BankAccount { BankName = "UniCredit Bulbank", Balance = 15000m, SwiftCode = "SWEDJHEWI" }; var paymentMethods = new PaymentMethod[] { new PaymentMethod() { User = user1, Type = PaymentMethodType.CreditCard, CreditCard = creditrcards[0], CreditCardId = 10 }, new PaymentMethod() { User = user1, Type = PaymentMethodType.CreditCard, CreditCard = creditrcards[1], CreditCardId = 10 }, new PaymentMethod() { User = user1, Type = PaymentMethodType.BankAccount, BankAccount = bankAccount } }; db.Users.Add(user1); db.CreditCards.AddRange(creditrcards); db.BankAccounts.Add(bankAccount); db.PaymentMethods.AddRange(paymentMethods); db.SaveChanges(); } }
static void Seed(BillsPaymentSystemContext context) { var users = new[] { new User { FirstName = "Miroslav", LastName = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Gosho", LastName = "Goshev", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Milen", LastName = "Toshev", Email = "*****@*****.**", Password = "******" }, new User { FirstName = "Ivan", LastName = "Popov", Email = "*****@*****.**", Password = "******" } }; context.Users.AddRange(users); var creditCards = new[] { new CreditCard(new DateTime(2018, 6, 20), 15000.00m, 1500.00m), new CreditCard(new DateTime(2018, 6, 25), 20000m, 1800m), new CreditCard(new DateTime(2019, 7, 4), 15000m, 14000m), new CreditCard(new DateTime(2019, 2, 5), 16000m, 4500m) }; context.CreditCards.AddRange(creditCards); var bankAccounts = new[] { new BankAccount(2455m, "Expresbank", "TGBHJKL"), new BankAccount(12000m, "Unicredit", "TBGINKFL"), new BankAccount(14000m, "UBB", "TBGDSK"), new BankAccount(8500m, "Raiffensen bank", "TBGFRF") }; context.BankAccounts.AddRange(bankAccounts); var paymentMethods = new[] { new PaymentMethod { User = users[0], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[0] }, new PaymentMethod { User = users[0], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[1] }, new PaymentMethod { User = users[0], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[0] }, new PaymentMethod { User = users[1], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[1] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[2] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[2] }, new PaymentMethod { User = users[2], Type = PaymentMethodType.CreditCard, CreditCard = creditCards[3] }, new PaymentMethod { User = users[3], Type = PaymentMethodType.BankAccount, BankAccount = bankAccounts[3] } }; context.PaymentMethods.AddRange(paymentMethods); context.SaveChanges(); }