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));
        }