Ejemplo n.º 1
0
        public static void DeleteBill(string deleteQueuedName)
        {
            using (var db = new BillContext())
            {
                var result = from r
                                 in db.Bills
                             where r.Name == deleteQueuedName
                             select r;
                //check if there is a record with this name

                if (result.Count() > 0)
                {
                    Bill product = result.First();
                    db.Bills.Remove(product);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        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.");
        }
Ejemplo n.º 3
0
        private static void EditBIll()
        {
            Console.WriteLine("Please select what do you want to change in the current bil:");
            Console.WriteLine("( 1 ) Name");
            Console.WriteLine("( 2 ) Fee");
            Console.WriteLine("( 3 ) First day for payment");
            Console.WriteLine("( 4 ) Last day for payment");
            Console.WriteLine("( 5 ) Has fixed fee");
            Console.WriteLine("( 6 ) Total amount");

            ConsoleKey currentUserChoise = Console.ReadKey().Key;

            if (currentUserChoise == ConsoleKey.D1)
            {
                using (var db = new BillContext())
                {
                    Console.WriteLine("Please select the name of the wanted bill: ");
                    string currentName = Console.ReadLine();
                    string newName = Console.ReadLine();
                    Bill original = (from bill
                                           in db.Bills
                                       where bill.Name == currentName
                                       select bill)
                                       .First();

                    original.Name = newName;
                    original.Fee = original.Fee;
                    original.FirstDayToPay = original.FirstDayToPay;
                    original.LastDayToPay = original.LastDayToPay;
                    original.HasFixedFee = original.HasFixedFee;
                    original.TotalAmount = original.TotalAmount;
                    db.SaveChanges();

                    Console.WriteLine("Done!");
                }
            }
        }