コード例 #1
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,HireDate")] Driver driver)
        {
            if (ModelState.IsValid)
            {
                db.Drivers.Add(driver);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(driver));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "TrackID,TrackName,TrackLocation")] Track track)
        {
            if (ModelState.IsValid)
            {
                db.Tracks.Add(track);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            return(View(track));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,HireDate")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                db.Teachers.Add(teacher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ID = new SelectList(db.LocationAssignments, "TeacherID", "Location", teacher.ID);
            return(View(teacher));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "CompanyID,CompanyName,CompanyLocation,StartDate,TeacherID")] Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TeacherID = new SelectList(db.Teachers, "ID", "LastName", company.TeacherID);
            return(View(company));
        }
コード例 #5
0
 public ActionResult Create([Bind(Include = "CarYear, CarMake, CarName, CarDescription")] Car car)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Cars.Add(car);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(car));
 }