public IActionResult WarBeast() { AddWarBeastViewModel view = new AddWarBeastViewModel ( context.Abilities.ToList(), context.Weapons.ToList(), context.Spells.ToList() ); return(View("AddWarBeast", view)); }
public IActionResult WarBeast(AddWarBeastViewModel model) { if (ModelState.IsValid) { WarBeast newBeast = new WarBeast(); newBeast.Name = model.Name; newBeast.ARM = model.ARM; newBeast.CMD = model.CMD; newBeast.DEF = model.DEF; newBeast.FA = model.FA; newBeast.MAT = model.MAT; newBeast.PointCost = model.PointCost; newBeast.RAT = model.RAT; newBeast.SPD = model.SPD; newBeast.STR = model.STR; newBeast.FA = model.FA; newBeast.Size = model.Size; newBeast.Threshhold = model.Threshold; newBeast.factionName = model.Faction; context.WarBeasts.Add(newBeast); context.SaveChanges(); if (model.abilIDS != null) { foreach (var abil in model.abilIDS) { WarBeastAbillity NewSoloAbility = new WarBeastAbillity(); NewSoloAbility.AbillityId = abil; NewSoloAbility.WarBeastid = newBeast.ID; context.WarbeastAbillities.Add(NewSoloAbility); context.SaveChanges(); } } if (model.weapIDS != null) { foreach (var weap in model.weapIDS) { WarbeastWeapon NewSoloWeapon = new WarbeastWeapon(); NewSoloWeapon.WeaponId = weap; NewSoloWeapon.WarbeastID = newBeast.ID; context.WarbeastWeapons.Add(NewSoloWeapon); context.SaveChanges(); } } if (model.spellIDS != null) { foreach (var spell in model.spellIDS) { WarbeastSpell NewSoloSpell = new WarbeastSpell(); NewSoloSpell.Spellid = spell; NewSoloSpell.WarbeastId = newBeast.ID; context.WarbeastSpells.Add(NewSoloSpell); context.SaveChanges(); } } return(Redirect("/")); } return(View("Warbeast", model)); }