public IActionResult CreateTourChiTiet(int id) { if (id == null) { return(NotFound()); } var tour = context.Tour.Find(id); if (tour == null) { return(NotFound()); } Console.WriteLine("chạy tới dây rồi."); var tourDiaDiem = from dd in context.TourDiaDiem where !((from ctdd in context.TourChiTiet where ctdd.TourId.Equals(id) select ctdd.DiaDiemId).Contains(dd.DiaDiemId)) select dd; foreach (var c in tourDiaDiem) { Console.WriteLine(c.DiaDiemTen); } ViewData["DiaDiemId"] = new SelectList(tourDiaDiem, "DiaDiemId", "DiaDiemTen"); ViewData["TourId"] = tour.TourTen; TourChiTiet tourChiTiet = new TourChiTiet(); tourChiTiet.TourId = id; return(View(tourChiTiet)); }
public async Task <IActionResult> CreateTourChiTiet([Bind("ChiTietId,DiaDiemId,ChiTietThuTu,NgayTao")] TourChiTiet tourChiTiet) { if (ModelState.IsValid) { tourChiTiet.TourId = (int)tourId; context.Add(tourChiTiet); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = tourChiTiet.TourId })); } ViewData["DiaDiemId"] = new SelectList(context.TourDiaDiem, "DiaDiemId", "DiaDiemTen", tourChiTiet.DiaDiemId); var tour = context.Tour.Find(tourId); ViewData["TourId"] = tour.TourTen; tourChiTiet.TourId = (int)tourId; return(View(tourChiTiet)); }
public async Task <IActionResult> EditTourChiTiet(int id, [Bind("ChiTietId,ChiTietThuTu,NgayTao")] TourChiTiet tourChiTiet) { if (id != tourChiTiet.ChiTietId) { return(NotFound()); } if (ModelState.IsValid) { try { var tct = await context.TourChiTiet.FindAsync(id); tct.ChiTietThuTu = tourChiTiet.ChiTietThuTu; context.Update(tct); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TourChiTietExists(tourChiTiet.ChiTietId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details), new { id = tourId })); } var diaDiem = await context.TourDiaDiem.FindAsync(tourChiTiet.DiaDiemId); var tour = await context.Tour.FindAsync(tourChiTiet.TourId); ViewData["DiaDiemId"] = diaDiem.DiaDiemTen; ViewData["TourId"] = tour.TourTen; return(View(tourChiTiet)); }