Exemple #1
0
        private object handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq     = (LoginRequest)request;
                AgencyUser   agencyUser = logReq.AgencyUser;
                try
                {
                    lock (server)
                    {
                        server.Login(agencyUser, this);
                    }
                    return(new OkResponse());
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request ...");
                LogoutRequest logReq     = (LogoutRequest)request;
                AgencyUser    agencyUser = logReq.AgencyUser;
                try
                {
                    lock (server)
                    {
                        server.Logout(agencyUser, this);
                    }
                    return(new OkResponse());
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetTripsRequest)
            {
                Console.WriteLine("Get Trips request");
                GetTripsRequest    getReq = (GetTripsRequest)request;
                IEnumerable <Trip> trips;
                try
                {
                    lock (server)
                    {
                        trips = server.FindAllTrips();
                    }
                    return(new GetTripsResponse(trips));
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetSearchedTripsRequest)
            {
                Console.WriteLine("Find searched trips request");
                GetSearchedTripsRequest getReq = (GetSearchedTripsRequest)request;
                TripDTO     tripDTO            = getReq.TripDTO;
                List <Trip> trips;

                try
                {
                    lock (server)
                    {
                        trips = (List <Trip>)server.SearchTripByTouristAttractionAndLeavingHour(tripDTO.TouristAttraction, tripDTO.Hour1, tripDTO.Hour2);
                    }
                    return(new GetSearchedTripsResponse(trips));
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is FindAgencyUserRequest)
            {
                Console.WriteLine("Finding agency user");
                FindAgencyUserRequest findReq       = (FindAgencyUserRequest)request;
                AgencyUserDTO         agencyUserDTO = findReq.AgencyUser;
                AgencyUser            agencyUser;
                try
                {
                    lock (server)
                    {
                        agencyUser = server.SearchAgencyUserByUserNameAndPassword(agencyUserDTO.userName, agencyUserDTO.password);
                    }
                    return(new FindAgencyUserResponse(agencyUser));
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is AddReservationRequest)
            {
                Console.WriteLine("Add Reservation Request");
                AddReservationRequest findReq     = (AddReservationRequest)request;
                Reservation           reservation = findReq.Reservation;
                try
                {
                    lock (server)
                    {
                        server.AddReservation(reservation);
                    }
                    return(new OkResponse());
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is UpdateTripRequest)
            {
                Console.WriteLine("Update Trip Request");
                UpdateTripRequest findReq = (UpdateTripRequest)request;
                Trip trip = findReq.Trip;
                try
                {
                    lock (server)
                    {
                        server.UpdateTrip(trip);
                    }
                    return(new OkResponse());
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is GetReservsationSizeRequest)
            {
                Console.WriteLine("Reservation Size Request");
                GetReservsationSizeRequest findReq = (GetReservsationSizeRequest)request;
                int size = 0;
                try
                {
                    lock (server)
                    {
                        size = server.GetReservationsSize();
                    }
                    return(new GetReservationSizeRespons(size));
                }
                catch (TouristAttractiontException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            return(response);
        }
 public FindAgencyUserRequest(AgencyUserDTO agencyUser)
 {
     this.agencyUser = agencyUser;
 }