Пример #1
0
        public bool CreatePokemon(PokemonCreate model)
        {
            var entity =
                new Pokemon()
            {
                PokemonName    = model.PokemonName,
                BaseExperience = model.BaseExperience,

                //Type 2 is nullable
                TypeID1 = model.PokemonTypeID1,
                TypeID2 = model.PokemonTypeID2,

                //Moves 2-4 are nullable
                MoveOneID   = model.MoveOneID,
                MoveTwoID   = model.MoveTwoID,
                MoveThreeID = model.MoveThreeID,
                MoveFourID  = model.MoveFourID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.PokemonDb.Add(entity);


                return(ctx.SaveChanges() == 1);
            }
        }
Пример #2
0
        //Create
        public bool CreatePokemon(PokemonCreate model)
        {
            Pokemon entity = new Pokemon
            {
                PokemonName = model.PokemonName,
                RegionID    = model.RegionID,
                TypeID      = model.TypeID,
                IsShiny     = model.IsShiny
            };

            _context.Pokemon.Add(entity);
            return(_context.SaveChanges() == 1);
        }
Пример #3
0
        public IHttpActionResult PostPokemon(PokemonCreate pokemon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreatePokemonService();

            if (!service.CreatePokemon(pokemon))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #4
0
        public bool CreatePokemon(PokemonCreate model)
        {
            var entity =
                new Pokemon()
            {
                PokemonName = model.PokemonName,
                PokemonType = model.PokemonType,
                DietType    = model.DietType,
                CreatedUtc  = DateTimeOffset.Now,
            };

            using (var ctx = new ApplicationDbContext())
            {
                Pokemon Pokemon = ctx.PokemonDb.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #5
0
        public ActionResult Create(PokemonCreate model)
        {
            if (ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreatePokemonService();

            if (service.CreatePokemon(model))
            {
                TempData["SaveResult"] = "Your Pokemon was added.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Pokmemon could not be added.");

            return(View(model));
        }