Exemplo n.º 1
0
        //Method to Delete a Guest and calling the validation methods from the GuestBiz class
        public static void DeleteGuest()
        {
            int  GuestID;
            bool GuestDeleted;

            try
            {
                //User Inputs
                Console.Write("Enter the Guest ID to be deleted : ");
                GuestID = Convert.ToInt32(Console.ReadLine());
                //Calling the GuestBL class to use it's function AND using NAMED ARGUMENTS
                GuestDeleted = GuestValidations.DeleteGuest(GuestID);

                if (GuestDeleted == true)
                {
                    Console.WriteLine("Guest Deleted Successfully!");
                }
                else
                {
                    throw new GuestPhoneBookException("Guest not deleted!");
                }
            }
            //Catching User defined exception
            catch (GuestPhoneBookException p)
            {
                Console.WriteLine(p.Message);
            }
            //Catching System exception
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public static void SearchGuest()
        {
            int   GuestID;
            Guest searchedGuest;

            try
            {
                Console.Write("Enter Guest ID for search : ");
                GuestID = Convert.ToInt32(Console.ReadLine());

                //Checking if all validations by calling the GuestBiz class to use it's function AND using are true AND using NAMED ARGUMENTS
                searchedGuest = GuestValidations.SearchGuest(GuestID: GuestID);

                if (searchedGuest != null)
                {
                    Console.WriteLine("Guest ID   : " + searchedGuest.GuestID);
                    Console.WriteLine("Guest Name : " + searchedGuest.GuestName);
                    Console.WriteLine("Guest Phone: " + searchedGuest.GuestContactNumber);
                }
                else
                {
                    throw new GuestPhoneBookException("Guest not found!");
                }
            }
            //Catching User defined exception
            catch (GuestPhoneBookException p)
            {
                Console.WriteLine(p.Message);
            }
            //Catching System exception
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 3
0
        //Method to Display a Guest and calling the validation methods from the GuestBiz class
        public static void DisplayGuest()
        {
            //Creating List object to store n number of inputs from the user
            List <Guest> GuestList = new List <Guest>();

            try
            {
                GuestList = GuestValidations.DisplayFromFile();
                if (GuestList.Count > 0)
                {
                    Console.WriteLine("*******************All Guest Detail****************");
                    Console.WriteLine("Guest ID     -    Guest Name   -    Guest Contact No   ");
                    Console.WriteLine("--------------------------------------------------------");
                    foreach (Guest p in GuestList)
                    {
                        Console.WriteLine(p.GuestID + "\t\t\t" + p.GuestName + "\t\t\t" + p.GuestContactNumber);
                    }
                }
                else
                {
                    throw new GuestPhoneBookException("There are no records!");
                }
            }
            //Catching User defined exception
            catch (GuestPhoneBookException p)
            {
                Console.WriteLine(p.Message);
            }
            //Catching System exception
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 4
0
        //
        private static void ListAllGuests()
        {
            List <Guest> Guests = GuestValidations.ReturnGuestInformation();

            foreach (Guest Guest in Guests)
            {
                Console.WriteLine("Guest ID is : {0}", Guest.GuestID);
                Console.WriteLine("Guest Name is : {0}", Guest.GuestName);
                Console.WriteLine("Guest Phone is : {0}", Guest.GuestContactNumber);
            }
        }
Exemplo n.º 5
0
        //Method to Update a Guest and calling the validation methods from the GuestBiz class
        public static void UpdateGuest()
        {
            Guest GuestToBeUpdated = new Guest();
            bool  GuestUpdated;

            try
            {
                //User inputs
                Console.Write("Enter Guest ID for which you would like to update the record : ");
                GuestToBeUpdated.GuestID = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter Guest Name to be updated : ");
                GuestToBeUpdated.GuestName = Console.ReadLine();
                Console.Write("Enter Guest Phone Number to be updated : ");
                GuestToBeUpdated.GuestContactNumber = Console.ReadLine();

                //Checking if all validations by calling the GuestBL class to use it's function AND using are true AND using NAMED ARGUMENTS
                GuestUpdated = GuestValidations.UpdateGuest(GuestToBeUpdated);

                //Checking if validations are true or not
                if (GuestUpdated == true)
                {
                    Console.WriteLine("Guest Updated Successfully!");
                }
                else
                {
                    throw new GuestPhoneBookException("Guest not updated!");
                }
            }
            //Catching User defined exception
            catch (GuestPhoneBookException p)
            {
                Console.WriteLine(p.Message);
            }
            //Catching System exception
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 6
0
        //Method to Add a Guest and calling the validation methods from the GuestBiz class
        public static void AddGuest()
        {
            try
            {
                //Creating object of Guest class to access the values being stored through the properties
                Guest newGuest = new Guest();

                //User Inputs
                Console.Write("Enter Guest ID : ");
                newGuest.GuestID = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter Guest Name : ");
                newGuest.GuestName = Console.ReadLine();
                Console.Write("Enter Guest Contact No : ");
                newGuest.GuestContactNumber = Console.ReadLine();

                //Checking if all validations by calling the GuestBL class to use it's function AND using are true AND using NAMED ARGUMENTS
                bool GuestAdded = GuestValidations.AddGuest(newGuest);
                if (GuestAdded == true)
                {
                    Console.WriteLine("Guest Added Successfully!");
                }
                else
                {
                    throw new GuestPhoneBookException("Guest not added! Please try again following the validations mentioned!");
                }
            }
            //Catching user defined exception
            catch (GuestPhoneBookException p)
            {
                Console.WriteLine(p.Message);
            }

            //Catching System exception
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 7
0
 public static void AddRecordsToFile()
 {
     GuestValidations.SerializeData();
     Console.WriteLine("Records Serialized and Successfully added to the file");
     Console.WriteLine();
 }