Skip to content

Commit 03cb040

Browse files
asp - migrate from newtonsoft
1 parent b390d59 commit 03cb040

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ASP.NET Core/Controllers/DataGridEmployeesByStateController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using ASP_NET_Core.Models;
99
using Microsoft.AspNetCore.Http;
1010
using Microsoft.AspNetCore.Mvc;
11-
using Newtonsoft.Json;
11+
using System.Text.Json;
1212

1313
namespace ASP_NET_Core.Controllers
1414
{
@@ -24,9 +24,8 @@ public object Get(DataSourceLoadOptions loadOptions)
2424
[HttpPost]
2525
public IActionResult Post(string values)
2626
{
27-
var newEmployee = new EmployeeByState();
28-
JsonConvert.PopulateObject(values, newEmployee);
29-
27+
var newEmployee = JsonSerializer.Deserialize<EmployeeByState>(values);
28+
newEmployee.ID = SampleData.DataGridEmployeesByState.Max(a => a.ID) + 1;
3029
if (!TryValidateModel(newEmployee))
3130
return BadRequest("Failed to insert item");
3231

@@ -40,7 +39,7 @@ public IActionResult Put(int key, string values)
4039
{
4140
var employee = SampleData.DataGridEmployeesByState.First(a => a.ID == key);
4241

43-
PopulateModel(JsonConvert.DeserializeObject<EmployeeByState>(values), employee);
42+
PopulateModel(JsonSerializer.Deserialize<EmployeeByState>(values), employee);
4443

4544
if (!TryValidateModel(employee))
4645
return BadRequest("Failed to update item");

0 commit comments

Comments
 (0)