public IActionResult Warcaster(int WarcasterId) { //create new model Warcaster Warcaster = context.Warcasters.Single(c => c.ID == WarcasterId); //get list of abilitiy IDS for the model List <WarcasterAbility> casterAbils = context.WarcasterAbilities.Where(c => c.WarcasterId == WarcasterId).ToList(); //create list to hold abils List <Ability> abilList = new List <Ability>(); //add each ability to list. foreach (WarcasterAbility abil in casterAbils) { abilList.Add(context.Abilities.Single(c => c.ID == abil.AbilityId)); } //set solo abilities to list we just made Warcaster.Abilities = abilList; List <WarcasterWeapon> lockWeapons = context.WarcasterWeapons.Where(c => c.WarcsaterId == WarcasterId).ToList(); List <Weapon> Weapons = new List <Weapon>(); foreach (WarcasterWeapon weapon in lockWeapons) { Weapons.Add(context.Weapons.Single(c => c.ID == weapon.WeaponId)); } Warcaster.Weapons = Weapons; List <WarcasterSpell> lockSpells = context.WarcasterSpells.Where(c => c.WarcasterId == WarcasterId).ToList(); List <Spell> Spells = new List <Spell>(); foreach (WarcasterSpell spell in lockSpells) { Spells.Add(context.Spells.Single(c => c.ID == spell.WarcasterId)); } Warcaster.Spells = Spells; ViewBag.Props = Warcaster.GetProps(); ViewBag.PropData = Helper.GetPropData(Warcaster.GetProps(), Warcaster); ViewBag.Type = "Warcaster"; return(View("Warcaster", Warcaster)); }
public IActionResult Warcaster(int SoloId) { Warcaster editModel = context.Warcasters.Single(c => c.ID == SoloId); EditWarcasterViewModel ViewModel = new EditWarcasterViewModel ( 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, Feat = editModel.Feat, currenntAbilIDs = context.WarcasterAbilities.Where(c => c.WarcasterId == SoloId).Select(x => x.AbilityId).ToList(), currenntSpellIDs = context.WarcasterSpells.Where(c => c.WarcasterId == SoloId).Select(x => x.SpellId).ToList(), currenntWeaponIDs = context.WarcasterWeapons.Where(c => c.WarcsaterId == SoloId).Select(x => x.WeaponId).ToList() }; ViewModel.SelecCurrenttWeapons(); ViewModel.SelectCurrenntSpells(); ViewModel.SelectCurrentAbillities(); return(View("EditWarcaster", ViewModel)); }
public IActionResult Warcaster(EditWarcasterViewModel editModel) { Warcaster editWarcaster = context.Warcasters.Single(c => c.ID == editModel.soloID); editWarcaster.ARM = editModel.ARM; editWarcaster.CMD = editModel.CMD; editWarcaster.DEF = editModel.DEF; editWarcaster.FA = editModel.FA; editWarcaster.MAT = editModel.MAT; editWarcaster.RAT = editModel.RAT; editWarcaster.Name = editModel.Name; editWarcaster.SPD = editModel.SPD; editWarcaster.PointCost = editModel.PointCost; editWarcaster.STR = editModel.STR; editWarcaster.factionName = editModel.Faction; editWarcaster.Feat = editModel.Feat; context.SaveChanges(); editModel.currenntAbilIDs = context.WarcasterAbilities.Where(c => c.WarcasterId == editWarcaster.ID).Select(x => x.AbilityId).ToList(); editModel.currenntSpellIDs = context.WarcasterSpells.Where(c => c.WarcasterId == editWarcaster.ID).Select(x => x.SpellId).ToList(); editModel.currenntWeaponIDs = context.WarcasterWeapons.Where(c => c.WarcsaterId == editWarcaster.ID).Select(x => x.WeaponId).ToList(); if (editModel.abilIDS != null) { foreach (var abil in editModel.abilIDS) { if (!editModel.currenntAbilIDs.Contains(abil)) { WarcasterAbility NewSoloAbility = new WarcasterAbility(); NewSoloAbility.AbilityId = abil; NewSoloAbility.WarcasterId = editModel.soloID; context.WarcasterAbilities.Add(NewSoloAbility); context.SaveChanges(); } foreach (var currentAbil in editModel.currenntAbilIDs) { if (!editModel.abilIDS.Contains(currentAbil)) { WarcasterAbility soloabil = (from s in context.WarcasterAbilities where s.AbilityId == currentAbil where s.WarcasterId == editModel.soloID select s).FirstOrDefault <WarcasterAbility>(); context.WarcasterAbilities.Remove(soloabil); context.SaveChanges(); } } } } else { // delete all solo abils var soloAbils = context.WarcasterAbilities.Where(c => c.WarcasterId == editModel.soloID).ToList(); foreach (var Abil in soloAbils) { context.WarcasterAbilities.Remove(Abil); context.SaveChanges(); } } if (editModel.weapIDS != null) { foreach (var weap in editModel.weapIDS) { if (!editModel.currenntWeaponIDs.Contains(weap)) { WarcasterWeapon NewSoloWeapon = new WarcasterWeapon(); NewSoloWeapon.WeaponId = weap; NewSoloWeapon.WarcsaterId = editModel.soloID; context.WarcasterWeapons.Add(NewSoloWeapon); context.SaveChanges(); } foreach (var weaps in editModel.currenntWeaponIDs) { if (!editModel.weapIDS.Contains(weaps)) { WarcasterWeapon soloWeap = (from s in context.WarcasterWeapons where s.WeaponId == weap where s.WarcsaterId == editModel.soloID select s).FirstOrDefault <WarcasterWeapon>(); context.WarcasterWeapons.Remove(soloWeap); context.SaveChanges(); } } } } else { // delete all solo abils var soloWeaps = context.WarcasterWeapons.Where(c => c.WarcsaterId == editModel.soloID).ToList(); foreach (var Weap in soloWeaps) { context.WarcasterWeapons.Remove(Weap); context.SaveChanges(); } } if (editModel.spellIDS != null) { foreach (var spell in editModel.spellIDS) { if (!editModel.currenntSpellIDs.Contains(spell)) { WarcasterSpell NewSoloSpell = new WarcasterSpell(); NewSoloSpell.SpellId = spell; NewSoloSpell.WarcasterId = editModel.soloID; context.WarcasterSpells.Add(NewSoloSpell); context.SaveChanges(); } foreach (var spells in editModel.currenntSpellIDs) { if (!editModel.spellIDS.Contains(spells)) { WarcasterSpell soloSpell = (from s in context.WarcasterSpells where s.SpellId == spell where s.WarcasterId == editModel.soloID select s).FirstOrDefault <WarcasterSpell>(); context.WarcasterSpells.Remove(soloSpell); context.SaveChanges(); } } } } else { // delete all solo abils var soloSpells = context.WarcasterSpells.Where(c => c.WarcasterId == editModel.soloID).ToList(); foreach (var Spell in soloSpells) { context.WarcasterSpells.Remove(Spell); context.SaveChanges(); } } return(Redirect("/View/Warcaster/" + editModel.soloID)); }
public IActionResult Warcaster(AddWarcasterViewModel model) { if (ModelState.IsValid) { Warcaster newSolo = new Warcaster(); newSolo.Name = model.Name; newSolo.ARM = model.ARM; newSolo.CMD = model.CMD; newSolo.DEF = model.DEF; newSolo.MAT = model.MAT; newSolo.PointCost = model.PointCost; newSolo.RAT = model.RAT; newSolo.SPD = model.SPD; newSolo.STR = model.STR; newSolo.WarjackPoints = model.WarjackPoints; newSolo.factionName = model.Faction; context.Warcasters.Add(newSolo); context.SaveChanges(); if (model.abilIDS != null) { foreach (var abil in model.abilIDS) { WarcasterAbility NewSoloAbility = new WarcasterAbility(); NewSoloAbility.AbilityId = abil; NewSoloAbility.WarcasterId = newSolo.ID; context.WarcasterAbilities.Add(NewSoloAbility); context.SaveChanges(); } } if (model.weapIDS != null) { foreach (var weap in model.weapIDS) { WarcasterWeapon NewSoloWeapon = new WarcasterWeapon(); NewSoloWeapon.WeaponId = weap; NewSoloWeapon.WarcsaterId = newSolo.ID; context.WarcasterWeapons.Add(NewSoloWeapon); context.SaveChanges(); } } if (model.spellIDS != null) { foreach (var spell in model.spellIDS) { WarcasterSpell NewSoloSpell = new WarcasterSpell(); NewSoloSpell.SpellId = spell; NewSoloSpell.WarcasterId = newSolo.ID; context.WarcasterSpells.Add(NewSoloSpell); context.SaveChanges(); } } return(Redirect("/")); } return(View("Warcaster", model)); }