Exemplo n.º 1
0
        private async void showRoutes(int?RouteID)
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            RouteRepository r = new RouteRepository();

            try
            {
                List <Route> routes;
                if (RouteID.GetValueOrDefault() > 0)
                {
                    routes = await r.GetRoutesByRegion(RouteID.GetValueOrDefault());
                }
                else
                {
                    routes = await r.GetRoutes();
                }
                routeList.ItemsSource = routes.OrderBy(e => e.ID);
            }
            catch (ApiException apiEx)
            {
                var sbuilder = new StringBuilder();
                sbuilder.AppendLine("Errors:");
                foreach (var error in apiEx.Errors)
                {
                    sbuilder.AppendLine("-" + error);
                }
                ProfessorOak.ShowMessage("Could not complete operation:", sbuilder.ToString());
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("server"))
                {
                    ProfessorOak.ShowMessage("Error", "No connection with the server.");
                }
                else
                {
                    ProfessorOak.ShowMessage("Error", "Could not complete operation.");
                }
            }
            finally
            {
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
        }
        private async void PopulateLists()
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            TypesRepository  t  = new TypesRepository();
            RouteRepository  r  = new RouteRepository();
            RegionRepository re = new RegionRepository();

            try
            {
                List <Types> types = await t.GetTypess();

                List <Route> route = await r.GetRoutes();

                List <Region> region = await re.GetRegions();

                types.Add(new Types {
                    ID = 0, TypeName = " - All Types"
                });
                route.Add(new Route {
                    ID = 0, RouteName = " - All Routes"
                });
                region.Add(new Region {
                    ID = 0, RegionName = " - All Regions"
                });
                App thisApp = Application.Current as App;
                thisApp.ActiveTypes   = types;
                thisApp.ActiveRoutes  = route;
                thisApp.ActiveRegions = region;
            }
            catch (ApiException apiEx)
            {
                var sbuilder = new StringBuilder();
                sbuilder.AppendLine("Errors: ");
                foreach (var error in apiEx.Errors)
                {
                    sbuilder.AppendLine("-" + error);
                }
                ProfessorOak.ShowMessage("Could not complete operation:", sbuilder.ToString());
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("Connection with the server"))
                {
                    ProfessorOak.ShowMessage("Error", "No connection with server. Ensure you have the proper connections and try again.");
                }
                else
                {
                    ProfessorOak.ShowMessage("Error", "Could not complete operation.");
                }
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
            finally
            {
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
        }