/// <summary>
        /// Editiranje pokemona
        /// </summary>
        private void PokemonStorageEditHelper()
        {
            int         box     = uxPokemonStorageBox.SelectedIndex;
            int         pokemon = uxPokemonStoragePokemon.SelectedIndex;
            PokemonEdit pe;

            if (uxPokemonStoragePokemon.Text != "Empty Slot")
            {
                pe = new PokemonEdit(pokemonStorage.PokemonBoxes[box, pokemon]);
                if (pe.ShowDialog() == DialogResult.OK)
                {
                    pokemonStorage.PokemonBoxes[box, pokemon] = pe.changedPokemon;
                    StorageBoxHelper();
                    if (pe.dexID != 0)
                    {
                        pokedex.pokedexOwn[pe.dexID - 1]  = true;
                        pokedex.pokedexSeen[pe.dexID - 1] = true;
                    }
                }
                else
                {
                    //Vracamo nepromjenjenog pokemona nazad u storage
                    pokemonStorage.PokemonBoxes[box, pokemon] = pe.originalPokemon;
                    StorageBoxHelper();
                }
                pe.Dispose();
                //Vracamo selektirani index koji je bio
                uxPokemonStoragePokemon.SelectedIndex = pokemon;
                return;
            }
            else
            {
                pe = new PokemonEdit(pokemonStorage.PokemonBoxes[box, pokemon], player);
                if (pe.ShowDialog() == DialogResult.OK)
                {
                    pokemonStorage.PokemonBoxes[box, pokemon] = pe.changedPokemon;
                    StorageBoxHelper();
                    if (pe.dexID != 0)
                    {
                        pokedex.pokedexOwn[pe.dexID - 1]  = true;
                        pokedex.pokedexSeen[pe.dexID - 1] = true;
                    }
                }
                else
                {
                    //Mora bit zbog reference
                    pokemonStorage.PokemonBoxes[box, pokemon].MakeBlankPokemonSpot();
                    StorageBoxHelper();
                }
                pe.Dispose();
                //Vracamo selektirani index koji je bio
                uxPokemonStoragePokemon.SelectedIndex = pokemon;
                return;
            }
        }
        public bool UpdatePokemon(PokemonEdit model, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx.PokemonDb
                    .Single(e => e.PokemonID == id);
                entity.PokemonName    = model.PokemonName;
                entity.BaseExperience = model.BaseExperience;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #3
0
        public bool UpdatePokemon(PokemonEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .PokemonDb
                    .Single(e => e.PokemonID == model.PokemonID);
                entity.PokemonName = model.PokemonName;
                entity.PokemonType = model.PokemonType;
                entity.DietType    = model.DietType;

                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult EditPokemon(PokemonEdit pokemon, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreatePokemonService();

            if (!service.UpdatePokemon(pokemon, id))
            {
                return(InternalServerError());
            }

            return(Ok());
        }