public IActionResult Solo(int SoloId)
        {
            List <Ability> AbilityList = context.Abilities.ToList();
            SoloModel      editSolo    = context.Solos.Single(c => c.ID == SoloId);

            EditSoloViewModel ViewModel = new
                                          EditSoloViewModel
                                          (

                context.Abilities.ToList(),
                context.Weapons.ToList(),
                context.Spells.ToList()
                                          )


            {
                ARM               = editSolo.ARM,
                CMD               = editSolo.CMD,
                DEF               = editSolo.DEF,
                FA                = editSolo.FA,
                MAT               = editSolo.MAT,
                RAT               = editSolo.RAT,
                Name              = editSolo.Name,
                SPD               = editSolo.SPD,
                PointCost         = editSolo.PointCost,
                STR               = editSolo.STR,
                soloID            = editSolo.ID,
                currenntAbilIDs   = context.SoloAbilities.Where(c => c.SoloID == SoloId).Select(x => x.AbilityID).ToList(),
                currenntSpellIDs  = context.SoloSpells.Where(c => c.SoloID == SoloId).Select(x => x.SpellID).ToList(),
                currenntWeaponIDs = context.SoloWeapons.Where(c => c.SoloID == SoloId).Select(x => x.WeaponID).ToList()
            };

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


            return(View("EditSolo", ViewModel));
        }
        public IActionResult Solo(EditSoloViewModel editModel)
        {
            SoloModel editSolo = context.Solos.Single(c => c.ID == editModel.soloID);



            editModel.currenntAbilIDs   = context.SoloAbilities.Where(c => c.SoloID == editModel.soloID).Select(i => i.AbilityID).ToList();
            editModel.currenntWeaponIDs = context.SoloWeapons.Where(c => c.SoloID == editModel.soloID).Select(x => x.WeaponID).ToList();
            editModel.currenntSpellIDs  = context.SoloSpells.Where(c => c.SoloID == editModel.soloID).Select(x => x.SpellID).ToList();



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



            if (editModel.abilIDS != null)
            {
                foreach (var abil in editModel.abilIDS)
                {
                    if (!editModel.currenntAbilIDs.Contains(abil))
                    {
                        SoloAbility NewSoloAbility = new SoloAbility();
                        NewSoloAbility.AbilityID = abil;
                        NewSoloAbility.SoloID    = editModel.soloID;
                        context.SoloAbilities.Add(NewSoloAbility);
                        context.SaveChanges();
                    }



                    foreach (var currentAbil in editModel.currenntAbilIDs)
                    {
                        if (!editModel.abilIDS.Contains(currentAbil))
                        {
                            SoloAbility soloabil = (from s in context.SoloAbilities where s.AbilityID == currentAbil where s.SoloID == editModel.soloID select s).FirstOrDefault <SoloAbility>();
                            context.SoloAbilities.Remove(soloabil);
                            context.SaveChanges();
                        }
                    }
                }
            }

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

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



            if (editModel.weapIDS != null)
            {
                foreach (var weap in editModel.weapIDS)
                {
                    if (!editModel.currenntWeaponIDs.Contains(weap))
                    {
                        SoloWeapon NewSoloWeapon = new SoloWeapon();
                        NewSoloWeapon.WeaponID = weap;
                        NewSoloWeapon.SoloID   = editModel.soloID;
                        context.SoloWeapons.Add(NewSoloWeapon);
                        context.SaveChanges();
                    }



                    foreach (var weaps in editModel.currenntWeaponIDs)
                    {
                        if (!editModel.weapIDS.Contains(weaps))
                        {
                            SoloWeapon soloWeap = (from s in context.SoloWeapons where s.WeaponID == weap where s.SoloID == editModel.soloID select s).FirstOrDefault <SoloWeapon>();
                            context.SoloWeapons.Remove(soloWeap);
                            context.SaveChanges();
                        }
                    }
                }
            }


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

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



            if (editModel.spellIDS != null)
            {
                foreach (var spell in editModel.spellIDS)
                {
                    if (!editModel.currenntSpellIDs.Contains(spell))
                    {
                        SoloSpell NewSoloSpell = new SoloSpell();
                        NewSoloSpell.SpellID = spell;
                        NewSoloSpell.SoloID  = editModel.soloID;
                        context.SoloSpells.Add(NewSoloSpell);
                        context.SaveChanges();
                    }



                    foreach (var spells in editModel.currenntSpellIDs)
                    {
                        if (!editModel.weapIDS.Contains(spells))
                        {
                            SoloSpell soloSpell = (from s in context.SoloSpells where s.SpellID == spell where s.SoloID == editModel.soloID select s).FirstOrDefault <SoloSpell>();
                            context.SoloSpells.Remove(soloSpell);
                            context.SaveChanges();
                        }
                    }
                }
            }


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

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



            return(Redirect("/View/Solo/" + editSolo.ID));
        }