コード例 #1
0
        //Function to delete Guest
        public static bool DeleteGuest(int GuestID)
        {
            bool  GuestDeleted     = true;
            Guest GuestToBeDeleted = null;

            try
            {
                //Search Guest in the records
                GuestToBeDeleted = GuestOperations.SearchGuest(GuestID);

                //If Guest is not null delete Guest otherwise raise exception
                if (GuestToBeDeleted != null)
                {
                    GuestDeleted = GuestOperations.DeleteGuest(GuestToBeDeleted);
                }
                else
                {
                    GuestDeleted = false;
                    throw new GuestPhoneBookException("Guest Info does not exists to delete");
                }
            }
            catch (GuestPhoneBookException p)
            {
                throw;
            }
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }

            return(GuestDeleted);
        }
コード例 #2
0
        //Function to search Guest Info using Guest ID
        public static Guest  SearchGuest(int GuestID)
        {
            Guest guestSearched = null;

            try
            {
                //Searching Guest
                guestSearched = GuestOperations.SearchGuest(GuestID);

                //If searched guest is null raise exception
                if (guestSearched == null)
                {
                    throw new GuestPhoneBookException("Guest Info does not exist!");
                }
            }
            catch (GuestPhoneBookException p)
            {
                throw;
            }
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }

            return(guestSearched);
        }
コード例 #3
0
        //Function to update Guest
        public static bool UpdateGuest(Guest guestToBeUpdated)
        {
            bool guestUpdated = true;

            try
            {
                //Searching Guest, if found update or raise exception
                if (GuestOperations.SearchGuest(guestToBeUpdated.GuestID) != null)
                {
                    //validating Guest, if valid update o.w. raise exception
                    if (ValidateGuest(guestToBeUpdated))
                    {
                        guestUpdated = GuestOperations.Updateguest(guestToBeUpdated);
                    }
                    else
                    {
                        guestUpdated = false;
                        throw new GuestPhoneBookException("Guest Info is not updated because it is not valid!");
                    }
                }
                else
                {
                    guestUpdated = false;
                    throw new GuestPhoneBookException("Guest id not exists for update!");
                }
            }
            catch (GuestPhoneBookException e)
            {
                throw;
            }
            catch (SystemException e)
            {
                Console.WriteLine(e.Message);
            }

            return(guestUpdated);
        }