Skip to content

Commit c97dcad

Browse files
Merge pull request #4 from DuckTieCorpMember/25.1.3+
Convert orig and fix examples
2 parents 9a7bc00 + 8e99d5f commit c97dcad

39 files changed

+18615
-15222
lines changed

ASP.NET Core/ASP.NET Core.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
</Target>
2121

2222
<ItemGroup>
23-
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.1.*" />
23+
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.1.3" />
24+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
2425
</ItemGroup>
2526

2627
</Project>

ASP.NET Core/Controllers/SampleDataController.cs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,75 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Http;
6+
using ASP.NET_Core.Models;
67
using ASP_NET_Core.Models;
78
using DevExtreme.AspNet.Data;
89
using DevExtreme.AspNet.Mvc;
910
using Microsoft.AspNetCore.Mvc;
10-
using System.Text.Json;
11+
using Newtonsoft.Json;
1112

1213
namespace ASP_NET_Core.Controllers;
1314

15+
[Route("api/[controller]/[action]")]
1416
[Route("api/[controller]/[action]")]
1517
public class SampleDataController: Controller {
16-
1718
[HttpGet]
18-
public object Get(DataSourceLoadOptions loadOptions) {
19-
return DataSourceLoader.Load(SampleData.Orders, loadOptions);
19+
public object GetStudents(DataSourceLoadOptions loadOptions) {
20+
return DataSourceLoader.Load(SampleData.Students, loadOptions);
2021
}
2122

2223
[HttpGet]
23-
public object GetStudents(DataSourceLoadOptions loadOptions)
24-
{
25-
return DataSourceLoader.Load(SampleData.Students, loadOptions);
24+
public object GetStudentSubjects(DataSourceLoadOptions loadOptions) {
25+
return DataSourceLoader.Load(SampleData.StudentSubjects, loadOptions);
2626
}
2727

2828
[HttpPost]
29-
public IActionResult InsertStudent(string values)
30-
{
31-
var newStudent = JsonSerializer.Deserialize<Student>(values, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
32-
if (newStudent == null) return BadRequest();
29+
public IActionResult InsertStudent(string values) {
30+
var newStudent = new Student();
31+
JsonConvert.PopulateObject(values, newStudent);
3332

3433
newStudent.ID = SampleData.Students.Count() + 1;
3534
SampleData.Students.Add(newStudent);
3635

3736
return Ok(newStudent);
3837
}
3938

39+
[HttpPost]
40+
public IActionResult InsertStudentSubject(string values) {
41+
var newStudentSubject = new StudentSubject();
42+
JsonConvert.PopulateObject(values, newStudentSubject);
43+
44+
newStudentSubject.ID = SampleData.StudentSubjects.Count() + 1;
45+
SampleData.StudentSubjects.Add(newStudentSubject);
46+
47+
return Ok(newStudentSubject);
48+
}
49+
4050
[HttpPut]
41-
public IActionResult UpdateStudent(int key, string values)
42-
{
51+
public IActionResult UpdateStudent(int key, string values) {
4352
var student = SampleData.Students.First(s => s.ID == key);
44-
var updatedStudent = JsonSerializer.Deserialize<Student>(values, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
45-
if (updatedStudent == null) return BadRequest();
46-
47-
student.Name = updatedStudent.Name ?? student.Name;
48-
student.Subjects = updatedStudent.Subjects ?? student.Subjects;
53+
JsonConvert.PopulateObject(values, student);
4954

5055
return Ok(student);
5156
}
5257

58+
[HttpPut]
59+
public IActionResult UpdateStudentSubject(int key, string values) {
60+
var studentSubject = SampleData.StudentSubjects.First(s => s.ID == key);
61+
JsonConvert.PopulateObject(values, studentSubject);
62+
63+
return Ok(studentSubject);
64+
}
65+
5366
[HttpDelete]
54-
public void DeleteStudent(int key)
55-
{
67+
public void DeleteStudent(int key) {
5668
var student = SampleData.Students.First(s => s.ID == key);
5769
SampleData.Students.Remove(student);
5870
}
5971

72+
[HttpDelete]
73+
public void DeleteStudentSubject(int key) {
74+
var studentSubject = SampleData.StudentSubjects.First(s => s.ID == key);
75+
SampleData.StudentSubjects.Remove(studentSubject);
76+
}
6077
}

0 commit comments

Comments
 (0)