private static void AddNewBill() { Console.Clear(); Console.WriteLine("To create new bill you need to enter the information needed. \r\nPress any key to continue!"); ConsoleKey clickToContinue = Console.ReadKey().Key; Console.Clear(); Console.WriteLine("Enter name:"); string newBillName = Console.ReadLine(); Console.Clear(); Console.WriteLine("Enter fee:"); double newBillFee = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Clear(); Console.WriteLine("New bill has fee: (1 or 0)"); int newBillHasFixedFee = int.Parse(Console.ReadLine()); Console.Clear(); double newBillTotalAmount; if (newBillHasFixedFee == 1) { Console.WriteLine("Total amount needed to be paid:"); newBillTotalAmount = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Clear(); } else { newBillTotalAmount = 0; } Console.WriteLine("First day for payment:"); int newBillFirstDayToPay = int.Parse(Console.ReadLine()); Console.Clear(); Console.WriteLine("Last day for payment:"); int newBillLastDayToPay = int.Parse(Console.ReadLine()); Console.Clear(); using (var db = new BillContext()) { var bill = new Bill() { Name = newBillName, Fee = newBillFee, HasFixedFee = newBillHasFixedFee, TotalAmount = newBillTotalAmount, FirstDayToPay = newBillFirstDayToPay, LastDayToPay = newBillLastDayToPay }; db.Bills.Add(bill); db.SaveChanges(); } Console.WriteLine("Done! The new bill is added to the database."); }
private static void CountNextBillForPayment() { using (var db = new BillContext()) { int minDateValue = int.MaxValue; var minDate = new Bill(); foreach (var bill in db.Bills) { if (bill.FirstDayToPay < minDateValue) { minDateValue = bill.FirstDayToPay; minDate = bill; } } Console.WriteLine("Next bill for payment: \r\nName:{0}, Fee:{1} {2}, First day:{3}", minDate.Name, minDate.Fee, currency, minDate.FirstDayToPay); } }