Beispiel #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.");
             }
         }
     }
 }
Beispiel #2
0
        public void SetPokemonStats(Pokemon pokemon)
        {
            Random random = new Random();

            pokemon.Happiness  = 100;
            pokemon.BirthDate  = DateTime.Now;
            pokemon.Growthrate = Convert.ToDecimal(random.NextDouble() * (1 - 0.7) + 0.7);
            _pokemonRepository.SetPokemonBaseStats(pokemon);
            _pokemonRepository.AddPokemon(pokemon);
        }