public ActionResult DeleteConfirmed(int id) { Thue_Phong thue_Phong = db.Thue_Phongs.Find(id); db.Thue_Phongs.Remove(thue_Phong); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "TP_ID,NgayThue,PhongID")] Thue_Phong thue_Phong) { if (ModelState.IsValid) { db.Entry(thue_Phong).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PhongID = new SelectList(db.Phongs, "PhongID", "TenPhong", thue_Phong.PhongID); return(View(thue_Phong)); }
public ActionResult Create([Bind(Include = "TP_ID,NgayThue,PhongID")] Thue_Phong thue_Phong) { if (ModelState.IsValid) { db.Thue_Phongs.Add(thue_Phong); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PhongID = new SelectList(db.Phongs, "PhongID", "TenPhong", thue_Phong.PhongID); return(View(thue_Phong)); }
// GET: Thue_Phong/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Thue_Phong thue_Phong = db.Thue_Phongs.Find(id); if (thue_Phong == null) { return(HttpNotFound()); } return(View(thue_Phong)); }
// GET: Thue_Phong/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Thue_Phong thue_Phong = db.Thue_Phongs.Find(id); if (thue_Phong == null) { return(HttpNotFound()); } ViewBag.PhongID = new SelectList(db.Phongs, "PhongID", "TenPhong", thue_Phong.PhongID); return(View(thue_Phong)); }
public ActionResult Create([Bind(Include = "PhongID,NgayThue,TenKhach,LoaiKhachID,CMND,DiaChi")] ThuePhongVM vm) { ViewBag.LoaiKhachID = new SelectList(db.Khach_Hangs, "LoaiKhachID", "LoaiKhach", vm.LoaiKhachID); ViewBag.PhongID = new SelectList(db.Phongs, "PhongID", "TenPhong", vm.PhongID); Phong phong = new Phong(); Khach_hang khach = new Khach_hang(); khach.LoaiKhach = khach.LoaiKhach; //phong.TenPhong = vm.TenPhong; //db.Phongs.Add(phong); //db.SaveChanges(); Thue_Phong thue = new Thue_Phong(); thue.NgayThue = vm.NgayThue; //thue.PhongID = phong.PhongID; db.Thue_Phongs.Add(thue); db.SaveChanges(); CT_Khach_Hang kh = new CT_Khach_Hang(); kh.TenKhach = vm.TenKhach; kh.CMND = vm.CMND; kh.DiaChi = vm.DiaChi; //kh.LoaiKhachID = khach.LoaiKhachID; db.CT_Khach_Hangs.Add(kh); db.SaveChanges(); CT_Thue_Phong cttp = new CT_Thue_Phong(); cttp.TP_ID = thue.TP_ID; cttp.KhachID = kh.KhachID; //cttp.Khach_Hang.LoaiKhachID = khach.LoaiKhachID; db.CT_Thue_Phongs.Add(cttp); db.SaveChanges(); //try //{ // if (ModelState.IsValid) // { // Phong phong = new Phong(); // Thue_Phong thue = new Thue_Phong(); // CT_Khach_Hang kh = new CT_Khach_Hang(); // CT_Thue_Phong cttp = new CT_Thue_Phong(); // db.Phongs.Add(phong); // db.Thue_Phongs.Add(thue); // db.CT_Khach_Hangs.Add(kh); // db.CT_Thue_Phongs.Add(cttp); // db.SaveChanges(); // return RedirectToAction("ListPhong", "ThuePhong_VM"); // } //} //catch (DbEntityValidationException eve) //{ // foreach (var ve in eve.EntityValidationErrors) // { // Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", // ve.PropertyName, // eve.Entry.CurrentValues.GetValue<object>(ve.PropertyName), // ve.ErrorMessage); // } // throw; //} SetAlert("Thêm phiếu thành công", "success"); return(RedirectToAction("ListPhong", "ThuePhong_VM")); }