Example #1
0
        public ActionResult Create(PhieuTiepNhan_Xe phieuTiepNhan_Xe)
        {
            if (ModelState.IsValid)
            {
                Xe            xe            = new Xe();
                PhieuTiepNhan phieuTiepNhan = new PhieuTiepNhan();
                //Add 1 xe
                xe.IDBienSo  = phieuTiepNhan_Xe.IDBienSo;
                xe.TenChuXe  = phieuTiepNhan_Xe.TenChuXe;
                xe.IDHieuXe  = phieuTiepNhan_Xe.IDHieuXe;
                xe.DiaChi    = phieuTiepNhan_Xe.DiaChi;
                xe.DienThoai = phieuTiepNhan_Xe.DienThoai;
                db.Xes.Add(xe);
                db.SaveChanges();
                //Add 1 Phieu tiep nhan
                int latestIDXe = xe.IDBienSo;
                phieuTiepNhan.IDBienSo     = latestIDXe;
                phieuTiepNhan.NgayTiepNhan = phieuTiepNhan_Xe.NgayTiepNhan;
                db.PhieuTiepNhans.Add(phieuTiepNhan);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.IDHieuXe = new SelectList(db.HieuXes, "IDHieuXe", "TenHieuXe", db.HieuXes.First().TenHieuXe);

            return(View(phieuTiepNhan_Xe));
        }
Example #2
0
        // GET: PhieuTiepNhans/Create
        //public ActionResult Create(int? id)
        //{
        //    if (id != null)
        //    {
        //        var xe = db.Xes.Where(i => i.IDBienSo == id);
        //        ViewBag.IDBienSo = new SelectList(xe, "IDBienSo", "TenChuXe",xe.First().TenChuXe);
        //        return View();
        //    }
        //    ViewBag.IDBienSo = new SelectList(db.Xes, "IDBienSo", "TenChuXe");
        //    return View();
        //}
        public ActionResult Create()
        {
            PhieuTiepNhan_Xe phieuTiepNhan_Xe = new PhieuTiepNhan_Xe();

            ViewBag.IDHieuXe = new SelectList(db.HieuXes, "IDHieuXe", "TenHieuXe", db.HieuXes.First().TenHieuXe);

            return(View(phieuTiepNhan_Xe));
        }