public ActionResult Create(PHIM phim, String theLoai, String quocGia) { if (ModelState.IsValid) { PHIM_THELOAI ptl = new PHIM_THELOAI(); ptl.Ma_phim = phim.Ma_phim; ptl.Ma_the_loai = theLoai; db.PHIM_THELOAI.Add(ptl); PHIM_QUOCGIA pqg = new PHIM_QUOCGIA(); pqg.Ma_phim = phim.Ma_phim; pqg.Ma_quoc_gia = quocGia; db.PHIM_QUOCGIA.Add(pqg); db.PHIMs.Add(phim); db.SaveChanges(); return RedirectToAction("Create","Home"); } ViewBag.DsTheLoai = new SelectList(db.THELOAIs.OrderBy(s => s.Ten_the_loai), "Ma_the_loai", "Ten_the_loai"); ViewBag.DsQuocGia = new SelectList(db.QUOCGIAs.OrderBy(s => s.Ten_quoc_gia), "Ma_quoc_gia", "Ten_quoc_gia"); return View(phim); }
public ActionResult Edit(PHIM phim, int postId, string theLoai, string quocGia) { if (ModelState.IsValid) { if(!String.IsNullOrEmpty(theLoai)) { var ds1 = db.PHIM_THELOAI.Where(s => s.Ma_phim.Equals(phim.Ma_phim)); foreach (var item in ds1) { db.PHIM_THELOAI.Remove(item); } PHIM_THELOAI ptl = new PHIM_THELOAI(); ptl.Ma_phim = phim.Ma_phim; ptl.Ma_the_loai = theLoai; db.PHIM_THELOAI.Add(ptl); } if(!String.IsNullOrEmpty(quocGia)) { var ds2 = db.PHIM_QUOCGIA.Where(s => s.Ma_phim.Equals(phim.Ma_phim)); foreach (var item in ds2) { db.PHIM_QUOCGIA.Remove(item); } PHIM_QUOCGIA pqg = new PHIM_QUOCGIA(); pqg.Ma_phim = phim.Ma_phim; pqg.Ma_quoc_gia = quocGia; db.PHIM_QUOCGIA.Add(pqg); } db.Entry(phim).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Edit", "Home", new { id = postId }); } ViewBag.DsTheLoai = new SelectList(db.THELOAIs.OrderBy(s=>s.Ten_the_loai), "Ma_the_loai", "Ten_the_loai"); ViewBag.DsQuocGia = new SelectList(db.QUOCGIAs.OrderBy(s=>s.Ten_quoc_gia), "Ma_quoc_gia", "Ten_quoc_gia"); return View(phim); }