예제 #1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "OrderID,UserID,TrackingID,City,State,Zip")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "FirstName", order.UserID);
            return(View(order));
        }
예제 #3
0
 public ActionResult Create([Bind(Include = "LastName,FirstName")] ApplicationUser applicationUser)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Users.Add(applicationUser);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException ex)
     {
         //Log the error
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(applicationUser));
 }
예제 #4
0
        public ActionResult Create([Bind(Include = "ApplicationUserID,TrackingNumber,Name,StreetAddress,City,State,Zip")] Order order)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Orders.Add(order);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException ex)
            {
                //Log the error
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            ViewBag.ApplicationUserID = new SelectList(db.Users, "ID", "LastName", order.ApplicationUserID);
            return(View(order));
        }