Ejemplo n.º 1
0
        public async Task <IActionResult> Create(NewSetViewModel newSetInfo)
        {
            //Create the new FullSet object
            FullSet newFullSet = new FullSet {
                SetName = newSetInfo.SetName
            };

            _db.FullSets.Add(newFullSet);

            //Grab the User, Profile, and Boss to add to join tables
            var user = await _userManager.GetUserAsync(User);

            Profile userProfile = _db.Profiles.FirstOrDefault(m => m.User == user);
            Boss    boss        = _db.Bosses.FirstOrDefault(m => m.Id == newSetInfo.BossId);

            //Add BossId to FullSet
            newFullSet.BossId = boss.Id;

            //**********Add To Join Tables**********

            //Profile Join Table
            ProfileFullSet newProfileSet = new ProfileFullSet {
                Profile = userProfile, FullSet = newFullSet
            };

            _db.ProfileFullSets.Add(newProfileSet);

            //Boss Join Table
            FullSetBoss newBossSet = new FullSetBoss {
                Boss = boss, BossId = boss.Id, FullSet = newFullSet
            };

            _db.FullSetBosses.Add(newBossSet);

            //Gear Join Table
            //HeadSlot
            FullSetGear headSlot = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.HeadSlotId)
            };

            _db.FullSetGears.Add(headSlot);
            //ChestSlot
            FullSetGear chestSlot = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.ChestSlotId)
            };

            _db.FullSetGears.Add(chestSlot);
            //LegSlot
            FullSetGear legSlot = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.LegSlotId)
            };

            _db.FullSetGears.Add(legSlot);
            //Boots
            FullSetGear boots = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.BootsId)
            };

            _db.FullSetGears.Add(boots);
            //Gloves
            FullSetGear gloves = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.GlovesId)
            };

            _db.FullSetGears.Add(gloves);
            //Cape
            FullSetGear cape = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.CapeId)
            };

            _db.FullSetGears.Add(cape);
            //Necklace
            FullSetGear necklace = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.NecklaceId)
            };

            _db.FullSetGears.Add(necklace);
            //Ring
            FullSetGear ring = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.RingId)
            };

            _db.FullSetGears.Add(ring);
            //ArrowSlot
            FullSetGear arrowSlot = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.ArrowSlotId)
            };

            _db.FullSetGears.Add(arrowSlot);
            //MainHand
            FullSetGear mainHand = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.MainHandId)
            };

            _db.FullSetGears.Add(mainHand);
            //OffHand
            FullSetGear offHand = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.OffHandId)
            };

            _db.FullSetGears.Add(offHand);
            //Spec Weapon
            FullSetGear specWeapon = new Models.FullSetGear {
                FullSet = newFullSet, Gear = _db.Gears.FirstOrDefault(m => m.Id == newSetInfo.SpecWeaponId)
            };

            _db.FullSetGears.Add(offHand);

            //Save All Changes
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(NewSetViewModel editFullSet)
        {
            //Find the fullset with the ID passed in
            FullSet editThis = _db.FullSets.FirstOrDefault(m => m.Id == editFullSet.FullSetId);

            editThis.SetName          = editFullSet.SetName;
            _db.Entry(editThis).State = EntityState.Modified;

            //Remove the previous FullSetGear objects and add the new ones
            //HeadSlot
            var deleteFSGheadslot = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.HeadSlotId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear headSlot = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.HeadSlotId)
            };

            _db.FullSetGears.Add(headSlot);
            //ChestSlot
            var deleteFSGchestslot = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.ChestSlotId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGchestslot);
            FullSetGear chestSlot = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.ChestSlotId)
            };

            _db.FullSetGears.Add(chestSlot);
            //LegSlot
            var deleteFSGlegslot = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.LegSlotId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear legSlot = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.LegSlotId)
            };

            _db.FullSetGears.Add(legSlot);
            //Boots
            var deleteFSGboots = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.BootsId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear boots = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.BootsId)
            };

            _db.FullSetGears.Add(boots);
            //Gloves
            var deleteFSGgloves = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.GlovesId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear gloves = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.GlovesId)
            };

            _db.FullSetGears.Add(gloves);
            //Cape
            var deleteFScape = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.CapeId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear cape = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.CapeId)
            };

            _db.FullSetGears.Add(cape);
            //Necklace
            var deleteFSGnecklace = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.NecklaceId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear necklace = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.NecklaceId)
            };

            _db.FullSetGears.Add(necklace);
            //Ring
            var deleteFSGring = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.RingId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear ring = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.RingId)
            };

            _db.FullSetGears.Add(ring);
            //ArrowSlot
            var deleteFSGarrowSlot = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.ArrowSlotId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear arrowSlot = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.ArrowSlotId)
            };

            _db.FullSetGears.Add(arrowSlot);
            //MainHand
            var deleteFSGmainHand = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.MainHandId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear mainHand = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.MainHandId)
            };

            _db.FullSetGears.Add(mainHand);
            //OffHand
            var deleteFSGoffHand = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.OffHandId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear offHand = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.OffHandId)
            };

            _db.FullSetGears.Add(offHand);
            //SpecWeapon
            var deleteFSGspecWeapon = _db.FullSetGears.FirstOrDefault(m => m.GearId == editFullSet.SpecWeaponId && m.FullSetId == editFullSet.FullSetId);

            _db.FullSetGears.Remove(deleteFSGheadslot);
            FullSetGear specWeapon = new Models.FullSetGear {
                FullSet = editThis, Gear = _db.Gears.FirstOrDefault(m => m.Id == editFullSet.SpecWeaponId)
            };

            _db.FullSetGears.Add(specWeapon);

            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }