public IActionResult Warbeast(int warbeastId) { //create new model WarBeast warbeast = context.WarBeasts.Single(c => c.ID == warbeastId); //get list of abilitiy IDS for the model List <WarBeastAbillity> beastAbils = context.WarbeastAbillities.Where(c => c.WarBeastid == warbeastId).ToList(); //create list to hold abils List <Ability> abilList = new List <Ability>(); //add each ability to list. foreach (WarBeastAbillity abil in beastAbils) { abilList.Add(context.Abilities.Single(c => c.ID == abil.AbillityId)); } //set solo abilities to list we just made warbeast.Abilities = abilList; List <WarbeastWeapon> beastWeapons = context.WarbeastWeapons.Where(c => c.WarbeastID == warbeastId).ToList(); List <Weapon> Weapons = new List <Weapon>(); foreach (WarbeastWeapon weapon in beastWeapons) { Weapons.Add(context.Weapons.Single(c => c.ID == weapon.WeaponId)); } warbeast.Weapons = Weapons; List <WarbeastSpell> beastSpells = context.WarbeastSpells.Where(c => c.WarbeastId == warbeastId).ToList(); List <Spell> Spells = new List <Spell>(); foreach (WarbeastSpell spell in beastSpells) { Spells.Add(context.Spells.Single(c => c.ID == spell.WarbeastId)); } warbeast.Spells = Spells; ViewBag.Props = warbeast.GetProps(); ViewBag.PropData = Helper.GetPropData(warbeast.GetProps(), warbeast); ViewBag.Type = "Warbeast"; return(View("Warbeast", warbeast)); }
public IActionResult WarBeast(int SoloId) { WarBeast editModel = context.WarBeasts.Single(c => c.ID == SoloId); EditWarBeastViewModel ViewModel = new EditWarBeastViewModel ( context.Abilities.ToList(), context.Weapons.ToList(), context.Spells.ToList() ) { ARM = editModel.ARM, CMD = editModel.CMD, DEF = editModel.DEF, FA = editModel.FA, MAT = editModel.MAT, RAT = editModel.RAT, Name = editModel.Name, SPD = editModel.SPD, PointCost = editModel.PointCost, STR = editModel.STR, soloID = editModel.ID, Size = editModel.Size, currenntAbilIDs = context.UnitAbilities.Where(c => c.UnitID == SoloId).Select(x => x.AbilityID).ToList(), currenntSpellIDs = context.UnitSpells.Where(c => c.UnitID == SoloId).Select(x => x.SpellID).ToList(), currenntWeaponIDs = context.UnitWeapons.Where(c => c.UnitID == SoloId).Select(x => x.WeaponId).ToList() }; ViewModel.SelecCurrenttWeapons(); ViewModel.SelectCurrenntSpells(); ViewModel.SelectCurrentAbillities(); return(View("EditWarBeast", ViewModel)); }
public IActionResult WarBeast(EditWarBeastViewModel editModel) { WarBeast editWarBeast = context.WarBeasts.Single(c => c.ID == editModel.soloID); editWarBeast.ARM = editModel.ARM; editWarBeast.CMD = editModel.CMD; editWarBeast.DEF = editModel.DEF; editWarBeast.FA = editModel.FA; editWarBeast.MAT = editModel.MAT; editWarBeast.RAT = editModel.RAT; editWarBeast.Name = editModel.Name; editWarBeast.SPD = editModel.SPD; editWarBeast.PointCost = editModel.PointCost; editWarBeast.STR = editModel.STR; editWarBeast.factionName = editModel.Faction; editWarBeast.Size = editModel.Size; context.SaveChanges(); editModel.currenntAbilIDs = context.WarbeastAbillities.Where(c => c.WarBeastid == editWarBeast.ID).Select(x => x.AbillityId).ToList(); editModel.currenntSpellIDs = context.WarbeastSpells.Where(c => c.WarbeastId == editWarBeast.ID).Select(x => x.Spellid).ToList(); editModel.currenntWeaponIDs = context.WarbeastWeapons.Where(c => c.WarbeastID == editWarBeast.ID).Select(x => x.WeaponId).ToList(); if (editModel.abilIDS != null) { foreach (var abil in editModel.abilIDS) { if (!editModel.currenntAbilIDs.Contains(abil)) { WarBeastAbillity NewSoloAbility = new WarBeastAbillity(); NewSoloAbility.AbillityId = abil; NewSoloAbility.WarBeastid = editModel.soloID; context.WarbeastAbillities.Add(NewSoloAbility); context.SaveChanges(); } foreach (var currentAbil in editModel.currenntAbilIDs) { if (!editModel.abilIDS.Contains(currentAbil)) { WarBeastAbillity soloabil = (from s in context.WarbeastAbillities where s.AbillityId == currentAbil where s.WarBeastid == editModel.soloID select s).FirstOrDefault <WarBeastAbillity>(); context.WarbeastAbillities.Remove(soloabil); context.SaveChanges(); } } } } else { // delete all solo abils var soloAbils = context.WarbeastAbillities.Where(c => c.WarBeastid == editModel.soloID).ToList(); foreach (var Abil in soloAbils) { context.WarbeastAbillities.Remove(Abil); context.SaveChanges(); } } if (editModel.weapIDS != null) { foreach (var weap in editModel.weapIDS) { if (!editModel.currenntWeaponIDs.Contains(weap)) { WarbeastWeapon NewSoloWeapon = new WarbeastWeapon(); NewSoloWeapon.WeaponId = weap; NewSoloWeapon.WarbeastID = editModel.soloID; context.WarbeastWeapons.Add(NewSoloWeapon); context.SaveChanges(); } foreach (var weaps in editModel.currenntWeaponIDs) { if (!editModel.weapIDS.Contains(weaps)) { WarbeastWeapon soloWeap = (from s in context.WarbeastWeapons where s.WeaponId == weap where s.WarbeastID == editModel.soloID select s).FirstOrDefault <WarbeastWeapon>(); context.WarbeastWeapons.Remove(soloWeap); context.SaveChanges(); } } } } else { // delete all solo abils var soloWeaps = context.WarbeastWeapons.Where(c => c.WarbeastID == editModel.soloID).ToList(); foreach (var Weap in soloWeaps) { context.WarbeastWeapons.Remove(Weap); context.SaveChanges(); } } if (editModel.spellIDS != null) { foreach (var spell in editModel.spellIDS) { if (!editModel.currenntSpellIDs.Contains(spell)) { WarbeastSpell NewSoloSpell = new WarbeastSpell(); NewSoloSpell.Spellid = spell; NewSoloSpell.WarbeastId = editModel.soloID; context.WarbeastSpells.Add(NewSoloSpell); context.SaveChanges(); } foreach (var spells in editModel.currenntSpellIDs) { if (!editModel.spellIDS.Contains(spells)) { WarbeastSpell soloSpell = (from s in context.WarbeastSpells where s.Spellid == spell where s.WarbeastId == editModel.soloID select s).FirstOrDefault <WarbeastSpell>(); context.WarbeastSpells.Remove(soloSpell); context.SaveChanges(); } } } } else { // delete all solo abils var soloSpells = context.WarbeastSpells.Where(c => c.WarbeastId == editModel.soloID).ToList(); foreach (var Spell in soloSpells) { context.WarbeastSpells.Remove(Spell); context.SaveChanges(); } } return(Redirect("/View/WarBeast/" + editModel.soloID)); }
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)); }