public async Task <IActionResult> Edit(int id, [Bind("DoanId,TourId,DoanTen,DoanNgayDi,DoanNgayVe,DoanChiTiet,DoanGiaTour,NgayTao")] TourDoan tourDoan) { if (id != tourDoan.DoanId) { return(NotFound()); } if (ModelState.IsValid) { try { var giaTourHienTai = context.GiaTourHienTai.Where(gtht => gtht.TourId == tourDoan.TourId).Include(gt => gt.Gia).FirstOrDefault(); tourDoan.DoanGiaTour = giaTourHienTai.Gia.GiaSoTien; context.Update(tourDoan); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TourDoanExists(tourDoan.DoanId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TourId"] = new SelectList(context.Tour, "TourId", "TourTen", tourDoan.TourId); return(View(tourDoan)); }
public async Task <IActionResult> Create([Bind("DoanId,TourId,DoanTen,DoanNgayDi,DoanNgayVe,DoanChiTiet,DoanGiaTour,NgayTao")] TourDoan tourDoan) { if (ModelState.IsValid) { var giaTourHienTai = context.GiaTourHienTai.Where(gtht => gtht.TourId == tourDoan.TourId).Include(gt => gt.Gia).FirstOrDefault(); tourDoan.DoanGiaTour = giaTourHienTai.Gia.GiaSoTien; context.Add(tourDoan); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TourId"] = new SelectList(context.Tour, "TourId", "TourTen", tourDoan.TourId); return(View(tourDoan)); }