Beispiel #1
0
        public IHttpActionResult Get()
        {
            try
            {
                var stations = _service.GetStations();
                var routes   = _service.GetRoutes();

                var originCodes      = routes.Select(r => r.Origin).Distinct().ToList();
                var destinationCodes = routes.Select(r => r.Destination).Distinct().ToList();

                var data = new StationsAndRoutesData
                {
                    Origins      = stations.Where(s => originCodes.Contains(s.Code)).OrderBy(s => s.Name).ToList(),
                    Destinations = stations.Where(s => destinationCodes.Contains(s.Code)).OrderBy(s => s.Name).ToList(),
                    Routes       = routes
                };

                return(Ok(data));
            }
            catch (Exception ex)
            {
                HandleServerError(ex);
                return(InternalServerError());
            }
        }