Esempio n. 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CT_Khach_Hang cT_Khach_Hang = db.CT_Khach_Hangs.Find(id);

            db.CT_Khach_Hangs.Remove(cT_Khach_Hang);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "KhachID,TenKhach,CMND,DiaChi,LoaiKhachID")] CT_Khach_Hang cT_Khach_Hang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cT_Khach_Hang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LoaiKhachID = new SelectList(db.Khach_Hangs, "LoaiKhachID", "LoaiKhach", cT_Khach_Hang.LoaiKhachID);
     return(View(cT_Khach_Hang));
 }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "KhachID,TenKhach,CMND,DiaChi,LoaiKhachID")] CT_Khach_Hang cT_Khach_Hang)
        {
            if (ModelState.IsValid)
            {
                db.CT_Khach_Hangs.Add(cT_Khach_Hang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LoaiKhachID = new SelectList(db.Khach_Hangs, "LoaiKhachID", "LoaiKhach", cT_Khach_Hang.LoaiKhachID);
            return(View(cT_Khach_Hang));
        }
Esempio n. 4
0
        // GET: CT_Khach_Hang/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CT_Khach_Hang cT_Khach_Hang = db.CT_Khach_Hangs.Find(id);

            if (cT_Khach_Hang == null)
            {
                return(HttpNotFound());
            }
            return(View(cT_Khach_Hang));
        }
Esempio n. 5
0
        // GET: CT_Khach_Hang/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CT_Khach_Hang cT_Khach_Hang = db.CT_Khach_Hangs.Find(id);

            if (cT_Khach_Hang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LoaiKhachID = new SelectList(db.Khach_Hangs, "LoaiKhachID", "LoaiKhach", cT_Khach_Hang.LoaiKhachID);
            return(View(cT_Khach_Hang));
        }
        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"));
        }