예제 #1
0
 [ValidateAntiForgeryToken] //Katso https://go.microsoft.com/fwlink/?LinkId=317598
 public ActionResult Edit([Bind(Include = "ShipperID,CompanyName,Phone,RegionID")] Shippers shipper)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shipper).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.RegionID = new SelectList(db.Region, "RegionID", "RegionDescription", shipper.RegionID);
         return(RedirectToAction("Index"));
     }
     return(View(shipper));
 }
예제 #2
0
        public ActionResult Create([Bind(Include = "accountId,username,password,createtime,lastlogintime,islogon,empolyeeid")] account account)
        {
            if (ModelState.IsValid)
            {
                account.accountId = Guid.NewGuid();
                db.accounts.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
        public ActionResult Create([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(orders);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", orders.CustomerID);
            ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", orders.EmployeeID);
            ViewBag.ShipVia    = new SelectList(db.Shippers, "ShipperID", "CompanyName", orders.ShipVia);
            return(View(orders));
        }
예제 #4
0
 [ValidateAntiForgeryToken] //Katso https://go.microsoft.com/fwlink/?LinkId=317598 tietoturvaan liittyvä
 public ActionResult Edit([Bind(Include = "ShipperID,CompanyName,Phone,RegionID")] Shippers shipper)
 // parametrina tuee Bind(Include = "sarakenimet")] Shippers tyyppinen shipper niminen olio
 // lomake palauttaa shipperin ja nuo sarakkeet/kentät kaivetaan ja shipper viedään tietokantaan alla olevalla koodilla
 {
     if (ModelState.IsValid)                             // jos ModelStare on validi eli ns. kaikki kunnossa
     {
         db.Entry(shipper).State = EntityState.Modified; // using system.data.entity käyttöön, jotta entitystate on tunnistettu
         // formista tuleva shipper olio tuodaan tähän Entry(shipper). db.Entry pävittää Staten ja sitten tallennetaan muutokset
         db.SaveChanges();
         ViewBag.RegionID = new SelectList(db.Region, "RegionID", "RegionDescription");  // tämä tuli tähän koska RegionID foreignkey lisättiin ja region joinattiin
         return(RedirectToAction("Index"));
     }
     return(View(shipper));
 }