Пример #1
0
        public override GetTripsResponse GetTrips(GetTripsRequest r)
        {
            var trips = new List <Trip>();

            if (activeTrips.Count > 0)
            {
                if (r.status != null)
                {
                    trips.AddRange(activeTrips.Values.Where(trip => trip.Status == r.status).ToList());
                }
                else
                {
                    trips.AddRange(activeTrips.Values);
                }
            }
            return(new GetTripsResponse(trips));
        }
Пример #2
0
 public override GetTripsResponse GetTrips(GetTripsRequest r)
 {
     var trips = new List<Trip>();
     if (activeTrips.Count > 0)
     {
         if (r.status != null)
             trips.AddRange(activeTrips.Values.Where(trip => trip.Status == r.status).ToList());
         else
             trips.AddRange(activeTrips.Values);
     }
     return new GetTripsResponse(trips);
 }
Пример #3
0
 public virtual GetTripsResponse GetTrips(GetTripsRequest request)
 {
     throw new Exception("Not supported");
 }
Пример #4
0
 virtual public GetTripsResponse GetTrips(GetTripsRequest request)
 {
     throw new Exception("Not supported");
 }
Пример #5
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);
        }