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));
        }
Beispiel #2
0
        public IActionResult Warlock(AddWarlockViewModel model)
        {
            if (ModelState.IsValid)
            {
                Warlock newSolo = new Warlock();


                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.WarbeastPoints = model.WarbeastPoints;
                newSolo.factionName    = model.Faction;


                context.Warlocks.Add(newSolo);
                context.SaveChanges();

                if (model.abilIDS != null)
                {
                    foreach (var abil in model.abilIDS)
                    {
                        WarlockAbillity NewSoloAbility = new WarlockAbillity();
                        NewSoloAbility.AbillityId = abil;
                        NewSoloAbility.WarlockId  = newSolo.ID;
                        context.WarlockAbillities.Add(NewSoloAbility);
                        context.SaveChanges();
                    }
                }


                if (model.weapIDS != null)
                {
                    foreach (var weap in model.weapIDS)
                    {
                        WarlockWeapon NewSoloWeapon = new WarlockWeapon();
                        NewSoloWeapon.WeaponId  = weap;
                        NewSoloWeapon.WarlockId = newSolo.ID;
                        context.WarlockWeapons.Add(NewSoloWeapon);
                        context.SaveChanges();
                    }
                }

                if (model.spellIDS != null)
                {
                    foreach (var spell in model.spellIDS)
                    {
                        WarlockSpell NewSoloSpell = new WarlockSpell();
                        NewSoloSpell.SpellId   = spell;
                        NewSoloSpell.WarlockId = newSolo.ID;
                        context.WarlockSpells.Add(NewSoloSpell);
                        context.SaveChanges();
                    }
                }



                return(Redirect("/"));
            }

            return(View("Warcaster", model));
        }