// zobrazení stránky NewBeast public async Task <ActionResult> NewBeast() { List <BeastTypeDO> beastType = await BeastTypeDO.GetBeastTypeAsync(); // hardcoded - allowing to add beasts only outside of towns List <LocationsDO> locations = await LocationsDO.GetLocationsAsync(1); ViewBag.beastType = beastType .Select(x => new SelectListItem() { Text = x.Name, Value = x.Idbeasttype.ToString() }) .ToList(); ViewBag.Location = locations .Select(x => new SelectListItem() { Text = x.Name, Value = x.LocationID.ToString() }) .ToList(); BeastModel model = new BeastModel(); return(View(model)); }
// zobrazení stránky Bestiary public async Task <ActionResult> Bestiary() { ViewBag.Message = "Bestiary page."; List <BeastTypeDO> beastType = await BeastTypeDO.GetBeastTypeAsync(); List <BeastsDO> bestiary = await BeastsDO.GetBeastsAsync(beastType[0].Idbeasttype); ViewBag.beastType = beastType .Select(x => new SelectListItem() { Text = x.Name, Value = x.Idbeasttype.ToString() }) .ToList(); ViewBag.Bestiary = bestiary; BeastModel model = new BeastModel(); model.BeastTypeID = beastType[0].Idbeasttype; return(View(model)); }
public async Task <ActionResult> NewBeast(BeastModel model) { List <BeastTypeDO> beastType = await BeastTypeDO.GetBeastTypeAsync(); // hardcoded - povoluje přidat bestie pouze mimo města List <LocationsDO> locations = await LocationsDO.GetLocationsAsync(0); ViewBag.beastType = beastType .Select(x => new SelectListItem() { Text = x.Name, Value = x.Idbeasttype.ToString() }) .ToList(); ViewBag.Location = locations .Select(x => new SelectListItem() { Text = x.Name, Value = x.LocationID.ToString() }) .ToList(); if (ModelState.IsValid) { if (model.BeastName != null && model.BeastBio != null) { using (fantasyDbEntities context = new fantasyDbEntities()) { // Vytvoření nové bestie a načtení hodnot zvolených uživatelem Bestiary beast = new Bestiary(); beast.name = model.BeastName; beast.bio = model.BeastBio; beast.hp = model.BeastHp; beast.attack = model.BeastAttack; beast.defense = model.BeastDefense; beast.locationid = model.BeastLocation; beast.beasttypeid = model.BeastTypeID; // Přidání řádku tabulky a uložení změn context.Bestiary.Add(beast); context.SaveChanges(); } } } return(RedirectToAction("Bestiary")); }
public async Task <ActionResult> Bestiary(BeastModel model) { List <BeastTypeDO> beastType = await BeastTypeDO.GetBeastTypeAsync(); List <BeastsDO> bestiary = await BeastsDO.GetBeastsAsync(model.BeastTypeID); ViewBag.beastType = beastType .Select(x => new SelectListItem() { Text = x.Name, Value = x.Idbeasttype.ToString() }) .ToList(); ViewBag.Bestiary = bestiary; return(View(model)); }