Exemple #1
0
 private async void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (Convert.ToInt32(pokemonNumberTextBox.Text) > 807 || Convert.ToInt32(pokemonNumberTextBox.Text) < 1)
     {
         ProfessorOak.ShowMessage("Error", "Pokemon Number is out of range. Must be between 1 and 807.");
     }
     else
     {
         try
         {
             View.Route = null;
             View.Types = null;
             PokemonRepository pr = new PokemonRepository();
             if (View.ID == 0)
             {
                 await pr.AddPokemon(View);
             }
             else
             {
                 await pr.UpdatePokemon(View);
             }
             Frame.GoBack();
         }
         catch (AggregateException ex)
         {
             string errorMsg = "";
             foreach (var exception in ex.InnerExceptions)
             {
                 errorMsg += Environment.NewLine + exception.Message;
             }
             ProfessorOak.ShowMessage("One or more exceptios have occured:", errorMsg);
         }
         catch (ApiException apiEx)
         {
             var sbuilder = new StringBuilder();
             sbuilder.AppendLine(string.Format("HTTP Status Code: {0}", apiEx.StatusCode.ToString()));
             sbuilder.AppendLine("Errors:");
             foreach (var error in apiEx.Errors)
             {
                 sbuilder.AppendLine("-" + error);
             }
             ProfessorOak.ShowMessage("There was a problem saving the Pokemon:", sbuilder.ToString());
         }
         catch (Exception ex)
         {
             if (ex.InnerException.Message.Contains("Connection with the server"))
             {
                 ProfessorOak.ShowMessage("Error", "No connection with the server.");
             }
             else
             {
                 ProfessorOak.ShowMessage("Error", "Could not complete operation.");
             }
         }
     }
 }
Exemple #2
0
 private void populateTypes()
 {
     try
     {
         App          thisApp = Application.Current as App;
         List <Types> types   = thisApp.ActiveTypes;
         TypesCombo.ItemsSource = types.Where(t => t.ID > 0).OrderBy(t => t.TypeName);
     }
     catch (Exception)
     {
         ProfessorOak.ShowMessage("Error", "No Types available. Refresh and try again.");
     }
 }
Exemple #3
0
 private void populateRoute()
 {
     try
     {
         App          thisApp = Application.Current as App;
         List <Route> route   = thisApp.ActiveRoutes;
         RouteCombo.ItemsSource = route.Where(r => r.ID > 0).OrderBy(r => r.RouteName);
     }
     catch (Exception)
     {
         ProfessorOak.ShowMessage("Error", "No Routes Available. Refresh and try again.");
     }
 }
 private void PopulateRegions()
 {
     try
     {
         App           thisApp = Application.Current as App;
         List <Region> regions = thisApp.ActiveRegions;
         RegionCombo.ItemsSource = regions.Where(r => r.ID > 0).OrderBy(r => r.RegionName);
     }
     catch (Exception)
     {
         ProfessorOak.ShowMessage("Error", "No Regions available. Refresh and try again.");
     }
 }
Exemple #5
0
        private async void showPokemon(int?RouteID)
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            PokemonRepository p = new PokemonRepository();

            try
            {
                List <Pokemon> pokemon;
                if (RouteID.GetValueOrDefault() > 0)
                {
                    pokemon = await p.GetPokemonsByRoute(RouteID.GetValueOrDefault());
                }
                else
                {
                    RoutePokemonListGrid.Visibility = Visibility.Collapsed;
                    return;
                    //pokemon = await p.GetPokemons();
                }
                RoutePokemonListPanel.ItemsSource = pokemon.OrderBy(e => e.Number);
            }
            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 connect with the server.");
                }
                else
                {
                    ProfessorOak.ShowMessage("Error", "Could not complete operation.");
                }
            }
            finally
            {
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
        }
        private async void showPokemon(/*int? TypesID*/ string typesName)
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;


            PokemonRepository p = new PokemonRepository();

            try
            {
                List <Pokemon> pokemon;
                if (/*TypesID.GetValueOrDefault() > 0*/ !string.IsNullOrEmpty(typesName))
                {
                    //pokemon = await p.GetPokemonsByTypes(TypesID.GetValueOrDefault());
                    pokemon = await p.GetPokemonsTypeIs(typesName.ToString());
                }
                else
                {
                    pokemon = await p.GetPokemons();
                }
                pokemonList.ItemsSource = pokemon.OrderBy(e => e.Number);
            }
            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;
            }
        }
Exemple #7
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 showTypes(string typeName)
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            TypesRepository t = new TypesRepository();

            try
            {
                List <Types> types;
                if (!string.IsNullOrEmpty(typeName))
                {
                    types = await t.GetTypesContains(typeName.ToString());
                }
                else
                {
                    types = await t.GetTypess();
                }
                TypesList.ItemsSource = types.OrderBy(e => e.TypeName);
            }
            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 server.");
                }
                else
                {
                    ProfessorOak.ShowMessage("Error", "Could not complete operation.");
                }
            }
            finally
            {
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
        }
 private async void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         View.Region = null;
         RouteRepository r = new RouteRepository();
         if (View.ID == 0)
         {
             await r.AddRoute(View);
         }
         else
         {
             await r.UpdateRoute(View);
         }
         Frame.GoBack();
     }
     catch (AggregateException ex)
     {
         string errorMsg = "";
         foreach (var exception in ex.InnerExceptions)
         {
             errorMsg += Environment.NewLine + exception.Message;
         }
         ProfessorOak.ShowMessage("One or more exceptions have occured:", errorMsg);
     }
     catch (ApiException apiEx)
     {
         var sbuilder = new StringBuilder();
         //sbuilder.AppendLine(string.Format("HTTP Status Code: {0}", apiEx.StatusCode.ToString()));
         sbuilder.AppendLine("Errors:");
         foreach (var error in apiEx.Errors)
         {
             sbuilder.AppendLine("-" + error);
         }
         ProfessorOak.ShowMessage("There was a problem saving the Route:", sbuilder.ToString());
     }
     catch (Exception ex)
     {
         if (ex.InnerException.Message.Contains("Connection with the server"))
         {
             ProfessorOak.ShowMessage("Error", "No connection with the server");
         }
         else
         {
             ProfessorOak.ShowMessage("Error", "Could not complete operation");
         }
     }
 }
        private async void showRegion()
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            RegionRepository r = new RegionRepository();

            try
            {
                List <Region> region;
                region = await r.GetRegions();

                RegionList.ItemsSource = region.OrderBy(e => e.RegionName);
            }
            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 server.");
                }
                else
                {
                    ProfessorOak.ShowMessage("Error", "Could not complete operation.");
                }
            }
            finally
            {
                progRing.IsActive   = false;
                progRing.Visibility = Visibility.Collapsed;
            }
        }
Exemple #11
0
        private async void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            string sTitle = "Confirm Delete";
            string sMsg   = "Are you certain you want to delete " + View.Name + "?";
            ContentDialogResult result = await ProfessorOak.ConfirmDialog(sTitle, sMsg);

            if (result == ContentDialogResult.Secondary)
            {
                try
                {
                    View.Route = null;
                    View.Types = null;
                    PokemonRepository pr = new PokemonRepository();
                    await pr.DeletePokemon(View);

                    Frame.GoBack();
                }
                catch (AggregateException ex)
                {
                    string errorMsg = "";
                    foreach (var exception in ex.InnerExceptions)
                    {
                        errorMsg += Environment.NewLine + exception.Message;
                    }
                    ProfessorOak.ShowMessage("One or more exceptions have occured:", errorMsg);
                }
                catch (ApiException apiEx)
                {
                    var sbuilder = new StringBuilder();
                    sbuilder.AppendLine("Errors:");
                    foreach (var error in apiEx.Errors)
                    {
                        sbuilder.AppendLine("-" + error);
                    }
                    ProfessorOak.ShowMessage("PRoblem deleting the Pokemon:", sbuilder.ToString());
                }
                catch (Exception)
                {
                    ProfessorOak.ShowMessage("Error", "Error deleting Pokemon");
                }
            }
        }
Exemple #12
0
        private void ddlPopulate()
        {
            progRing.IsActive   = true;
            progRing.Visibility = Visibility.Visible;

            try
            {
                App           thisApp = Application.Current as App;
                List <Region> regions = thisApp.ActiveRegions;
                RegionCombo.ItemsSource = regions.OrderBy(r => r.RegionName);
                //btnAdd.IsEnabled = true;
                showRoutes(null);
                showPokemon(null);
            }
            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 the 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;
            }
        }
        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;
            }
        }