Skip to content

Commit 63c629a

Browse files
Fix aspnetcore
1 parent 7e76ae5 commit 63c629a

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

ASP.NET Core/Controllers/EmployeesDataController.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using DevExtreme.AspNet.Data;
88
using DevExtreme.AspNet.Mvc;
99
using Microsoft.AspNetCore.Mvc;
10-
using Newtonsoft.Json;
10+
using System.Text.Json;
1111

1212
namespace ASP_NET_Core.Controllers
1313
{
@@ -25,8 +25,7 @@ public object Get(DataSourceLoadOptions loadOptions)
2525
[HttpPost]
2626
public IActionResult Post(string values)
2727
{
28-
var newItem = new Employee();
29-
JsonConvert.PopulateObject(values, newItem);
28+
var newItem = JsonSerializer.Deserialize<Employee>(values);
3029
EmployeesData.Employees.Add(newItem);
3130
return Ok();
3231
}
@@ -35,7 +34,14 @@ public IActionResult Post(string values)
3534
public IActionResult Put(int key, string values)
3635
{
3736
var employee = EmployeesData.Employees.FirstOrDefault(e => e.ID == key);
38-
JsonConvert.PopulateObject(values, employee);
37+
if (employee != null)
38+
{
39+
var updatedEmployee = JsonSerializer.Deserialize<Employee>(values);
40+
employee.ID = updatedEmployee.ID;
41+
employee.FirstName = updatedEmployee.FirstName;
42+
employee.LastName = updatedEmployee.LastName;
43+
employee.City = updatedEmployee.City;
44+
}
3945
return Ok();
4046
}
4147

ASP.NET Core/package-lock.json

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)