예제 #1
0
        [HttpPost]//接收USER輸入的新增資料
        public ActionResult Insert()
        {
            Categories _category = new Categories();

            _category.CategoryName    = Request.Form["CategoryName"];
            _category.Description     = Request.Form["Description"];
            db.Entry(_category).State = EntityState.Added;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public IHttpActionResult PutCustomer(string id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
 public ActionResult Update(Customers willUpdated, bool isUpdate)
 {
     if (!string.IsNullOrEmpty(willUpdated.CustomerID))
     {
         var updatedEntity = dbModel.Entry(willUpdated);
         updatedEntity.State = System.Data.Entity.EntityState.Modified;
         dbModel.SaveChanges();
         return(RedirectToAction("Detail", new { userID = willUpdated.CustomerID, isUpdate = true }));
     }
     else
     {
         var added = dbModel.Entry(willUpdated);
         added.State = System.Data.Entity.EntityState.Added;
         dbModel.SaveChanges();
         return(RedirectToAction("Detail", new { userID = added.Entity.CustomerID, isUpdate = false }));
     }
 }
예제 #5
0
 public ActionResult Edit([Bind(Include = "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
예제 #6
0
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", product.SupplierID);
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", order.CustomerID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", order.EmployeeID);
     ViewBag.ShipVia    = new SelectList(db.Shippers, "ShipperID", "CompanyName", order.ShipVia);
     return(View(order));
 }
예제 #8
0
        public IHttpActionResult PutProducts(int id, Products viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != viewModel.ProductID)
            {
                return(BadRequest());
            }

            //db.Entry(viewModel).State = EntityState.Modified;

            var produto = db.Products.Find();

            db.Entry(produto).CurrentValues.SetValues(viewModel);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }