public void AddPokemon(PokemonViewModel model) { using (PokemonGoContext context = new PokemonGoContext()) { Main main = new Main(); main.AddDate = DateTime.Now; main.EvolvedFrom = model.EvolvedFrom; main.Height = model.Height; main.HeightCategory = model.HeightCategoryId; main.PokemonId = model.PokemonId; main.SpecialAttack = model.SpecialAttack; main.StandardAttack = model.StandardAttack; main.TrainerLevelCaught = model.TrainerLevelCaught; main.Weight = model.Weight; main.WeightCategory = model.WeightCategoryId; main.XId = model.XId; main.UserId = model.UserId; context.Add(main); context.SaveChanges(); PowerLevel level = new PowerLevel(); level.AddDate = DateTime.Now; level.CP = model.PowerLevel.CP; level.HP = model.PowerLevel.HP; level.MainId = main.Id; level.PowerPercent = model.PowerLevel.PowerPercent; level.PowerUpDust = model.PowerLevel.PowerUpDust; level.TrainerLevel = model.PowerLevel.TrainerLevel; context.Add(level); context.SaveChanges(); } }
public ActionResult Evolve(int mainId) { PokemonService service = new Services.PokemonService(); Main ancestor = service.GetPokemon(mainId); PokemonViewModel viewModel = new PokemonViewModel(service.GetCategories(), service.GetPokemon(), service.GetSpecialAttacks(), service.GetStandardAttacks(), service.GetUsers()); viewModel.EvolvedFrom = ancestor.XId; return View("Index", viewModel); }
public ActionResult Index(PokemonViewModel viewModel) { try { PokemonService service = new PokemonService(); service.AddPokemon(viewModel); //return RedirectToAction("Index", new { id = viewModel.XId }); return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }
public ActionResult Index(Guid? id) { PokemonService service = new Services.PokemonService(); PokemonViewModel viewModel = new PokemonViewModel(); if (id.HasValue) { Main main = service.GetPokemon(id.Value); List<PowerLevel> powerLevels = service.GetPowerLevels(main.Id); viewModel = new PokemonViewModel(main, powerLevels, service.GetCategories(), service.GetPokemon(), service.GetSpecialAttacks(), service.GetStandardAttacks(), service.GetUsers()); } else { viewModel = new PokemonViewModel(service.GetCategories(), service.GetPokemon(), service.GetSpecialAttacks(), service.GetStandardAttacks(), service.GetUsers()); } return View(viewModel); }