示例#1
0
        /// <summary>
        /// method for reading the order
        /// </summary>
        public void Read()
        {
            // input and validation
            Console.WriteLine("Input code of record you want to view");
            bool isValid = int.TryParse(Console.ReadLine(), out int code);

            while (isValid == false)
            {
                Console.WriteLine("Wrong input, please try again.");
                isValid = int.TryParse(Console.ReadLine(), out code);
            }


            try
            {
                using (RestaurantBraticGacinovicEntities context = new RestaurantBraticGacinovicEntities())
                {
                    // finding the order in the database with ID
                    tblRecord       recordToView = (from x in context.tblRecords where x.Code == code select x).First();
                    List <tblOrder> list         = (from x in context.tblOrders where x.RecordID == recordToView.RecordID select x).ToList();

                    // displaying the order
                    foreach (var item in list)
                    {
                        Console.WriteLine(item.Article + " " + item.Quantity);
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }
示例#2
0
        /// <summary>
        /// method for deleting the order
        /// </summary>
        public void Delete()
        {
            // inputs and validations
            Console.WriteLine("Input code of record you want to delete");
            bool isValid = int.TryParse(Console.ReadLine(), out int code);

            while (isValid == false)
            {
                Console.WriteLine("Wrong input, please try again.");
                isValid = int.TryParse(Console.ReadLine(), out code);
            }

            try
            {
                // finding the order and deleting it from the database
                using (RestaurantBraticGacinovicEntities context = new RestaurantBraticGacinovicEntities())
                {
                    tblRecord       recordToDelete = (from x in context.tblRecords where x.Code == code select x).First();
                    List <tblOrder> list           = (from x in context.tblOrders where x.RecordID == recordToDelete.RecordID select x).ToList();
                    context.tblOrders.RemoveRange(list);
                    context.tblRecords.Remove(recordToDelete);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }
示例#3
0
        /// <summary>
        /// method for creating the order
        /// </summary>
        public void Create()
        {
            // dictionary for displaying the restaurant Menu
            Dictionary <int, string> RestaurantMenu = ShowMenu();

            try
            {
                using (RestaurantBraticGacinovicEntities context = new RestaurantBraticGacinovicEntities())
                {
                    tblRecord record = new tblRecord();
                    Random    rnd    = new Random();

                    // variables for creating record in table Records and taking random order code
                    record.OrderTime = DateTime.Now;
                    record.Code      = rnd.Next(1, 9999);
                    context.tblRecords.Add(record);

                    string exit = null;

                    // loop for creating the order
                    do
                    {
                        // inputs and validations
                        Console.WriteLine("Input ID of the article: ");
                        bool isValid = int.TryParse(Console.ReadLine(), out int id);

                        while (isValid == false)
                        {
                            Console.WriteLine("Wrong input, please try again.");
                            isValid = int.TryParse(Console.ReadLine(), out id);
                        }

                        // loop for checking if the article exists in the Menu
                        if (!RestaurantMenu.ContainsKey(id))
                        {
                            Console.WriteLine("The article does not exist.");
                            return;
                        }

                        Console.WriteLine("Input quantity: ");
                        bool inputQuantity = int.TryParse(Console.ReadLine(), out int quantity);

                        while (inputQuantity == false)
                        {
                            Console.WriteLine("Wrong input, please try again.");
                            inputQuantity = int.TryParse(Console.ReadLine(), out quantity);
                        }

                        // loop for checking if article exists and creating the order
                        if (RestaurantMenu.ContainsKey(id))
                        {
                            tblOrder order = new tblOrder();
                            order.Article  = RestaurantMenu[id];
                            order.Quantity = quantity;
                            order.RecordID = record.RecordID;
                            context.tblOrders.Add(order);
                        }


                        Console.WriteLine("If you want to finish order press 'x', or press 'enter' to continue.");
                        exit = Console.ReadLine();
                    } while (exit != "x");

                    Console.WriteLine("\nCode of your order: " + record.Code);


                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }
示例#4
0
        /// <summary>
        /// method for updating orders, deleting the order and creating new with the same code and ID
        /// </summary>
        public void Update()
        {
            // inputs and validations
            Console.Write("Please enter your order code: ");
            bool isValid = int.TryParse(Console.ReadLine(), out int code);

            while (isValid == false)
            {
                Console.WriteLine("Wrong input, please try again.");
                isValid = int.TryParse(Console.ReadLine(), out code);
            }

            // calling method for displaying the restaurant Menu
            Dictionary <int, string> RestaurantMenu = ShowMenu();

            try
            {
                using (RestaurantBraticGacinovicEntities context = new RestaurantBraticGacinovicEntities())
                {
                    tblRecord record = new tblRecord();

                    // finding order to edit
                    tblRecord       recordToEdit = (from x in context.tblRecords where x.Code == code select x).First();
                    List <tblOrder> list         = (from y in context.tblOrders where y.RecordID == recordToEdit.RecordID select y).ToList();

                    // deleting the order
                    context.tblOrders.RemoveRange(list);
                    if (recordToEdit != null)
                    {
                        string exit = null;

                        // loop for creating new order at the same code and ID
                        do
                        {
                            Console.WriteLine("Input ID of the article: ");
                            bool inputID = int.TryParse(Console.ReadLine(), out int id);

                            while (inputID == false)
                            {
                                Console.WriteLine("Wrong input, please try again.");
                                inputID = int.TryParse(Console.ReadLine(), out id);
                            }

                            Console.WriteLine("Input quantity: ");
                            bool inputQuantity = int.TryParse(Console.ReadLine(), out int quantity);

                            while (inputID == false)
                            {
                                Console.WriteLine("Wrong input, please try again.");
                                inputQuantity = int.TryParse(Console.ReadLine(), out quantity);
                            }

                            // creating new order
                            if (RestaurantMenu.ContainsKey(id))
                            {
                                tblOrder order = new tblOrder();
                                order.Article  = RestaurantMenu[id];
                                order.Quantity = quantity;
                                order.RecordID = recordToEdit.RecordID;
                                context.tblOrders.Add(order);
                            }
                            Console.WriteLine("\nIf you want to finish order press 'x', or press 'enter' to continue.");
                            exit = Console.ReadLine();
                        } while (exit != "x");

                        context.SaveChanges();
                    }
                    else
                    {
                        Console.WriteLine("\nYour order does not exist, please try again.");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }