public async Task <ActionResult> AddToTrip(string comboId) { var list = comboId.Split(","); int gearId = Int32.Parse(list[0]); int tripId = Int32.Parse(list[1]); var gearTripData = new GearTrip() { GearId = gearId, TripId = tripId }; var alreadyAddedGearTrip = await _context.GearTrips.FirstOrDefaultAsync(g => g.GearId == gearTripData.GearId && g.TripId == gearTripData.TripId); if (alreadyAddedGearTrip == null) { _context.GearTrips.Add(gearTripData); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", "GearTrips", new { tripId = tripId })); } else { TempData["alreadyAdded"] = "That item is already packed."; return(RedirectToAction("Edit", "GearTrips", new { tripId = tripId })); } }
private void AddSingleGearTrip(int tripId, int gearId) { var gearTripData = new GearTrip() { GearId = gearId, TripId = tripId }; _context.GearTrips.Add(gearTripData); }