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



            EditWarjackViewModel ViewModel = new
                                             EditWarjackViewModel
                                             (

                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("EditWarjack", ViewModel));
        }
        public IActionResult Warjack(EditWarjackViewModel editModel)
        {
            Warjack editWarjack = context.Warjacks.Single(c => c.ID == editModel.soloID);



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

            editModel.currenntAbilIDs = context.WarjackAbilities.Where(c => c.WarjackID == editWarjack.ID).Select(x => x.AbillityID).ToList();

            editModel.currenntWeaponIDs = context.WarjackWeapons.Where(c => c.WarjackId == editWarjack.ID).Select(x => x.WeaponId).ToList();



            if (editModel.abilIDS != null)
            {
                foreach (var abil in editModel.abilIDS)
                {
                    if (!editModel.currenntAbilIDs.Contains(abil))
                    {
                        WarjackAbillity NewSoloAbility = new WarjackAbillity();
                        NewSoloAbility.AbillityID = abil;
                        NewSoloAbility.WarjackID  = editModel.soloID;
                        context.WarjackAbilities.Add(NewSoloAbility);
                        context.SaveChanges();
                    }



                    foreach (var currentAbil in editModel.currenntAbilIDs)
                    {
                        if (!editModel.abilIDS.Contains(currentAbil))
                        {
                            WarjackAbillity soloabil = (from s in context.WarjackAbilities where s.AbillityID == currentAbil where s.WarjackID == editModel.soloID select s).FirstOrDefault <WarjackAbillity>();
                            context.WarjackAbilities.Remove(soloabil);
                            context.SaveChanges();
                        }
                    }
                }
            }

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

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



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



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


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

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



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