public async Task <IActionResult> AddUsersFirstNewGearSettings(GearGrouped GearGroup) { foreach (SettingKnobViewModel item in GearGroup.GearSettings) { ChannelToGear channelToGear = new ChannelToGear { KnobSetting = item.ChannelToGear.KnobSetting, GearId = item.ChannelToGear.GearId, ChannelId = item.ChannelToGear.ChannelId, KnobId = item.ChannelToGear.KnobId }; _context.Add(channelToGear); await _context.SaveChangesAsync(); } return(RedirectToAction("Details", "Channels", new { id = GearGroup.GearSettings[0].ChannelToGear.ChannelId })); }
public async Task <IActionResult> AddUsersFirstNewGearSettings(int id, string GearTitle) { if (id == null) { return(NotFound()); } GearGrouped KnobNamesToEdit = new GearGrouped(); KnobNamesToEdit.GearSettings = new List <SettingKnobViewModel>(); var getChannel = await _context.Channel .FirstAsync(ch => ch.ChannelId == id); var getGear = await _context.Gear .Include(g => g.Knobs) .FirstOrDefaultAsync(g => g.GearId == int.Parse(GearTitle)); KnobNamesToEdit.TypeId = getGear.GearId; KnobNamesToEdit.GearMake = getGear.Make; KnobNamesToEdit.GearModel = getGear.Model; foreach (Knob item in getGear.Knobs) { SettingKnobViewModel specifics = new SettingKnobViewModel(); specifics.KnobLabel = item.KnobName; specifics.Setting = "Setting"; specifics.ChannelToGear = new ChannelToGear { KnobSetting = "Setting", GearId = int.Parse(GearTitle), ChannelId = id, Channel = getChannel, KnobId = item.KnobId, Knob = item }; KnobNamesToEdit.GearSettings.Add(specifics); } return(View(KnobNamesToEdit)); }