Skip to content

Commit 5dc086b

Browse files
committed
Fix the update action metods to save changes into the database
1 parent e3b3802 commit 5dc086b

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

grid/odata-v4-web-api-binding-wrappers/KendoUIMVC5/Controllers/EmployeesController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ public IQueryable<Employee> GetEmployees()
3535
}
3636

3737
// PUT: odata/Employees(5)
38-
public IHttpActionResult Put([FromODataUri] int key, Employee test)
38+
public IHttpActionResult Put([FromODataUri] int key, Employee employee)
3939
{
4040
if (!ModelState.IsValid)
4141
{
4242
return BadRequest(ModelState);
4343
}
4444

45-
Employee Employee = db.Employees.Find(key);
4645
if (!ModelState.IsValid)
4746
{
4847
return BadRequest(ModelState);
4948
}
5049

51-
if (key != Employee.EmployeeID)
50+
if (key != employee.EmployeeID)
5251
{
5352
return BadRequest();
5453
}
5554

56-
db.Entry(Employee).State = EntityState.Modified;
55+
db.Employees.Attach(employee);
56+
db.Entry(employee).State = EntityState.Modified;
5757

5858
try
5959
{
@@ -71,7 +71,7 @@ public IHttpActionResult Put([FromODataUri] int key, Employee test)
7171
}
7272
}
7373

74-
return Updated(Employee);
74+
return Updated(employee);
7575
}
7676

7777
private bool EmployeeExists(int key)

grid/odata-v4-web-api-binding-wrappers/KendoUIMVC5/Controllers/ProductsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ public IQueryable<Product> GetProducts()
3636
}
3737

3838
// PUT: odata/Products(5)
39-
public IHttpActionResult Put([FromODataUri] int key, Product test)
39+
public IHttpActionResult Put([FromODataUri] int key, Product product)
4040
{
4141
if (!ModelState.IsValid)
4242
{
4343
return BadRequest(ModelState);
4444
}
4545

46-
Product product = db.Products.Find(key);
4746
if (!ModelState.IsValid)
4847
{
4948
return BadRequest(ModelState);
@@ -54,6 +53,7 @@ public IHttpActionResult Put([FromODataUri] int key, Product test)
5453
return BadRequest();
5554
}
5655

56+
db.Products.Attach(product);
5757
db.Entry(product).State = EntityState.Modified;
5858

5959
try
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

grid/odata-v4-web-api-binding/OdataTest/Controllers/EmployeesController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ public IQueryable<Employee> GetEmployees()
3535
}
3636

3737
// PUT: odata/Employees(5)
38-
public IHttpActionResult Put([FromODataUri] int key, Employee test)
38+
public IHttpActionResult Put([FromODataUri] int key, Employee employee)
3939
{
4040
if (!ModelState.IsValid)
4141
{
4242
return BadRequest(ModelState);
4343
}
4444

45-
Employee Employee = db.Employees.Find(key);
4645
if (!ModelState.IsValid)
4746
{
4847
return BadRequest(ModelState);
4948
}
5049

51-
if (key != Employee.EmployeeID)
50+
if (key != employee.EmployeeID)
5251
{
5352
return BadRequest();
5453
}
5554

56-
db.Entry(Employee).State = EntityState.Modified;
55+
db.Employees.Attach(employee);
56+
db.Entry(employee).State = EntityState.Modified;
5757

5858
try
5959
{
@@ -71,7 +71,7 @@ public IHttpActionResult Put([FromODataUri] int key, Employee test)
7171
}
7272
}
7373

74-
return Updated(Employee);
74+
return Updated(employee);
7575
}
7676

7777
private bool EmployeeExists(int key)

0 commit comments

Comments
 (0)