public IActionResult Warlock(int SoloId)
        {
            Warlock editModel = context.Warlocks.Single(c => c.ID == SoloId);



            EditWarlockViewModel ViewModel = new
                                             EditWarlockViewModel
                                             (

                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.WarlockAbillities.Where(c => c.WarlockId == SoloId).Select(x => x.AbillityId).ToList(),
                currenntSpellIDs  = context.WarlockSpells.Where(c => c.WarlockId == SoloId).Select(x => x.SpellId).ToList(),
                currenntWeaponIDs = context.WarjackWeapons.Where(c => c.WarjackId == SoloId).Select(x => x.WeaponId).ToList()
            };

            ViewModel.SelecCurrenttWeapons();
            ViewModel.SelectCurrenntSpells();
            ViewModel.SelectCurrentAbillities();


            return(View("EditWarlock", ViewModel));
        }
        public IActionResult Warlock(EditWarlockViewModel editModel)
        {
            Warlock editWarlock = context.Warlocks.Single(c => c.ID == editModel.soloID);



            editWarlock.ARM         = editModel.ARM;
            editWarlock.CMD         = editModel.CMD;
            editWarlock.DEF         = editModel.DEF;
            editWarlock.FA          = editModel.FA;
            editWarlock.MAT         = editModel.MAT;
            editWarlock.RAT         = editModel.RAT;
            editWarlock.Name        = editModel.Name;
            editWarlock.SPD         = editModel.SPD;
            editWarlock.PointCost   = editModel.PointCost;
            editWarlock.STR         = editModel.STR;
            editWarlock.factionName = editModel.Faction;
            editWarlock.Feat        = editModel.Feat;
            context.SaveChanges();

            editModel.currenntAbilIDs   = context.WarlockAbillities.Where(c => c.WarlockId == editWarlock.ID).Select(x => x.AbillityId).ToList();
            editModel.currenntSpellIDs  = context.WarlockSpells.Where(c => c.WarlockId == editWarlock.ID).Select(x => x.SpellId).ToList();
            editModel.currenntWeaponIDs = context.WarlockWeapons.Where(c => c.WarlockId == editWarlock.ID).Select(x => x.WeaponId).ToList();



            if (editModel.abilIDS != null)
            {
                foreach (var abil in editModel.abilIDS)
                {
                    if (!editModel.currenntAbilIDs.Contains(abil))
                    {
                        WarlockAbillity NewSoloAbility = new WarlockAbillity();
                        NewSoloAbility.AbillityId = abil;
                        NewSoloAbility.WarlockId  = editModel.soloID;
                        context.WarlockAbillities.Add(NewSoloAbility);
                        context.SaveChanges();
                    }



                    foreach (var currentAbil in editModel.currenntAbilIDs)
                    {
                        if (!editModel.abilIDS.Contains(currentAbil))
                        {
                            WarlockAbillity soloabil = (from s in context.WarlockAbillities where s.AbillityId == currentAbil where s.WarlockId == editModel.soloID select s).FirstOrDefault <WarlockAbillity>();
                            context.WarlockAbillities.Remove(soloabil);
                            context.SaveChanges();
                        }
                    }
                }
            }

            else
            {
                // delete all solo abils
                var soloAbils = context.WarlockAbillities.Where(c => c.WarlockId == editModel.soloID).ToList();

                foreach (var Abil in soloAbils)
                {
                    context.WarlockAbillities.Remove(Abil);
                    context.SaveChanges();
                }
            }



            if (editModel.weapIDS != null)
            {
                foreach (var weap in editModel.weapIDS)
                {
                    if (!editModel.currenntWeaponIDs.Contains(weap))
                    {
                        WarlockWeapon NewSoloWeapon = new WarlockWeapon();
                        NewSoloWeapon.WeaponId  = weap;
                        NewSoloWeapon.WarlockId = editModel.soloID;
                        context.WarlockWeapons.Add(NewSoloWeapon);
                        context.SaveChanges();
                    }



                    foreach (var weaps in editModel.currenntWeaponIDs)
                    {
                        if (!editModel.weapIDS.Contains(weaps))
                        {
                            WarlockWeapon soloWeap = (from s in context.WarlockWeapons where s.WeaponId == weap where s.WarlockId == editModel.soloID select s).FirstOrDefault <WarlockWeapon>();
                            context.WarlockWeapons.Remove(soloWeap);
                            context.SaveChanges();
                        }
                    }
                }
            }


            else
            {
                // delete all solo abils
                var soloWeaps = context.WarlockWeapons.Where(c => c.WarlockId == editModel.soloID).ToList();

                foreach (var Weap in soloWeaps)
                {
                    context.WarlockWeapons.Remove(Weap);
                    context.SaveChanges();
                }
            }



            if (editModel.spellIDS != null)
            {
                foreach (var spell in editModel.spellIDS)
                {
                    if (!editModel.currenntSpellIDs.Contains(spell))
                    {
                        WarlockSpell NewSoloSpell = new WarlockSpell();
                        NewSoloSpell.SpellId   = spell;
                        NewSoloSpell.WarlockId = editModel.soloID;
                        context.WarlockSpells.Add(NewSoloSpell);
                        context.SaveChanges();
                    }



                    foreach (var spells in editModel.currenntSpellIDs)
                    {
                        if (!editModel.spellIDS.Contains(spells))
                        {
                            WarlockSpell soloSpell = (from s in context.WarlockSpells where s.SpellId == spell where s.WarlockId == editModel.soloID select s).FirstOrDefault <WarlockSpell>();
                            context.WarlockSpells.Remove(soloSpell);
                            context.SaveChanges();
                        }
                    }
                }
            }


            else
            {
                // delete all solo abils
                var soloSpells = context.WarlockSpells.Where(c => c.WarlockId == editModel.soloID).ToList();

                foreach (var Spell in soloSpells)
                {
                    context.WarlockSpells.Remove(Spell);
                    context.SaveChanges();
                }
            }



            return(Redirect("/View/Warlock/" + editModel.soloID));
        }