Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76d9631

Browse files
Updated the sample.
1 parent 80a34f7 commit 76d9631

File tree

276 files changed

+9811
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+9811
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This file explains how Visual Studio created the project.
2+
3+
The following steps were used to generate this project:
4+
- Create new ASP\.NET Core Web API project.
5+
- Update `launchSettings.json` to register the SPA proxy as a startup assembly.
6+
- Update project file to add a reference to the frontend project and set SPA properties.
7+
- Add project to the startup projects list.
8+
- Write this file.
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.ComponentModel.DataAnnotations;
3+
using System.Data;
4+
using Syncfusion.EJ2.Base;
5+
using Microsoft.Data.SqlClient;
6+
7+
namespace Grid_MSSQL.Server.Controllers
8+
{
9+
[ApiController]
10+
public class GridController : ControllerBase
11+
{
12+
13+
string ConnectionString = @"<Enter a valid connection string>";
14+
15+
[HttpPost]
16+
[Route("api/[controller]")]
17+
public object Post([FromBody] DataManagerRequest DataManagerRequest)
18+
{
19+
// Retrieve data from the data source (e.g., database).
20+
IQueryable<Orders> DataSource = GetOrderData().AsQueryable();
21+
22+
// Initialize QueryableOperation instance.
23+
QueryableOperation queryableOperation = new QueryableOperation();
24+
25+
// Handling searching operation.
26+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
27+
{
28+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
29+
//Add custom logic here if needed and remove above method.
30+
}
31+
32+
// Handling filtering operation.
33+
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
34+
{
35+
foreach (WhereFilter condition in DataManagerRequest.Where)
36+
{
37+
foreach (WhereFilter predicate in condition.predicates)
38+
{
39+
DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator);
40+
//Add custom logic here if needed and remove above method.
41+
}
42+
}
43+
}
44+
45+
// Handling Sorting operation.
46+
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
47+
{
48+
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
49+
//Add custom logic here if needed and remove above method.
50+
}
51+
52+
53+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
54+
{
55+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
56+
//Add custom logic here if needed and remove above method.
57+
}
58+
59+
// Get the total count of records.
60+
int totalRecordsCount = DataSource.Count();
61+
62+
// Handling paging operation.
63+
if (DataManagerRequest.Skip != 0)
64+
{
65+
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
66+
//Add custom logic here if needed and remove above method.
67+
}
68+
if (DataManagerRequest.Take != 0)
69+
{
70+
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
71+
//Add custom logic here if needed and remove above method.
72+
}
73+
74+
// Return data based on the request.
75+
return new { result = DataSource, count = totalRecordsCount };
76+
}
77+
78+
79+
/// <summary>
80+
/// Retrieves the order data from the database.
81+
/// </summary>
82+
/// <returns>Returns a list of orders fetched from the database.</returns>
83+
[HttpGet]
84+
[Route("api/[controller]")]
85+
public List<Orders> GetOrderData()
86+
{
87+
string queryStr = "SELECT * FROM dbo.Orders ORDER BY OrderID;";
88+
SqlConnection sqlConnection = new(ConnectionString);
89+
sqlConnection.Open();
90+
SqlCommand sqlCommand = new(queryStr, sqlConnection);
91+
SqlDataAdapter DataAdapter = new(sqlCommand);
92+
DataTable DataTable = new();
93+
DataAdapter.Fill(DataTable);
94+
sqlConnection.Close();
95+
96+
// Map data to a list.
97+
List<Orders> dataSource = (from DataRow Data in DataTable.Rows
98+
select new Orders()
99+
{
100+
OrderID = Convert.ToInt32(Data["OrderID"]),
101+
CustomerID = Data["CustomerID"].ToString(),
102+
EmployeeID = Convert.IsDBNull(Data["EmployeeID"]) ? 0 : Convert.ToUInt16(Data["EmployeeID"]),
103+
ShipCity = Data["ShipCity"].ToString(),
104+
Freight = Convert.ToDecimal(Data["Freight"])
105+
}).ToList();
106+
return dataSource;
107+
}
108+
109+
110+
/// <summary>
111+
/// Inserts a new data item into the data collection.
112+
/// </summary>
113+
/// <param name="value">It contains the new record detail which is need to be inserted.</param>
114+
/// <returns>Returns void.</returns>
115+
[HttpPost]
116+
[Route("api/[controller]/Insert")]
117+
public void Insert([FromBody] CRUDModel<Orders> value)
118+
{
119+
//Create query to insert the specific into the database by accessing its properties.
120+
string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{value.value.CustomerID}','{value.value.Freight}','{value.value.ShipCity}','{value.value.EmployeeID}')";
121+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
122+
SqlConnection.Open();
123+
124+
//Execute the SQL command.
125+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
126+
127+
//Execute this code to reflect the changes into the database.
128+
SqlCommand.ExecuteNonQuery();
129+
SqlConnection.Close();
130+
131+
//Add custom logic here if needed and remove above method.
132+
}
133+
134+
135+
/// <summary>
136+
/// Update a existing data item from the data collection.
137+
/// </summary>
138+
/// <param name="value">It contains the updated record detail which is need to be updated.</param>
139+
/// <returns>Returns void.</returns>
140+
[HttpPost]
141+
[Route("api/[controller]/Update")]
142+
public void Update([FromBody] CRUDModel<Orders> value)
143+
{
144+
//Create query to update the changes into the database by accessing its properties.
145+
string queryStr = $"Update Orders set CustomerID='{value.value.CustomerID}', Freight='{value.value.Freight}',EmployeeID='{value.value.EmployeeID}',ShipCity='{value.value.ShipCity}' where OrderID='{value.value.OrderID}'";
146+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
147+
SqlConnection.Open();
148+
149+
//Execute the SQL command.
150+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
151+
152+
//Execute this code to reflect the changes into the database.
153+
SqlCommand.ExecuteNonQuery();
154+
SqlConnection.Close();
155+
156+
//Add custom logic here if needed and remove above method.
157+
}
158+
159+
/// <summary>
160+
/// Remove a specific data item from the data collection.
161+
/// </summary>
162+
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
163+
/// <return>Returns void.</return>
164+
[HttpPost]
165+
[Route("api/[controller]/Remove")]
166+
public void Remove([FromBody] CRUDModel<Orders> value)
167+
{
168+
//Create query to remove the specific from database by passing the primary key column value.
169+
string queryStr = $"Delete from Orders where OrderID={value.key}";
170+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
171+
SqlConnection.Open();
172+
173+
//Execute the SQL command.
174+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
175+
176+
//Execute this code to reflect the changes into the database.
177+
SqlCommand.ExecuteNonQuery();
178+
SqlConnection.Close();
179+
180+
//Add custom logic here if needed and remove above method.
181+
}
182+
183+
184+
/// <summary>
185+
/// Batch update (Insert, Update, and Delete) a collection of data items from the data collection.
186+
/// </summary>
187+
/// <param name="value">The set of information along with details about the CRUD actions to be executed from the database.</param>
188+
/// <returns>Returns void.</returns>
189+
[HttpPost]
190+
[Route("api/[controller]/BatchUpdate")]
191+
public IActionResult BatchUpdate([FromBody] CRUDModel<Orders> value)
192+
{
193+
if (value.changed != null && value.changed.Count > 0)
194+
{
195+
foreach (Orders Record in (IEnumerable<Orders>)value.changed)
196+
{
197+
//Create query to update the changes into the database by accessing its properties.
198+
string queryStr = $"Update Orders set CustomerID='{Record.CustomerID}', Freight='{Record.Freight}',EmployeeID='{Record.EmployeeID}',ShipCity='{Record.ShipCity}' where OrderID='{Record.OrderID}'";
199+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
200+
SqlConnection.Open();
201+
202+
//Execute the SQL command.
203+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
204+
205+
//Execute this code to reflect the changes into the database.
206+
SqlCommand.ExecuteNonQuery();
207+
SqlConnection.Close();
208+
209+
//Add custom logic here if needed and remove above method.
210+
}
211+
}
212+
if (value.added != null && value.added.Count > 0)
213+
{
214+
foreach (Orders Record in (IEnumerable<Orders>)value.added)
215+
{
216+
//Create query to insert the specific into the database by accessing its properties.
217+
string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{Record.CustomerID}','{Record.Freight}','{Record.ShipCity}','{Record.EmployeeID}')";
218+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
219+
SqlConnection.Open();
220+
221+
//Execute the SQL command.
222+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
223+
224+
//Execute this code to reflect the changes into the database.
225+
SqlCommand.ExecuteNonQuery();
226+
SqlConnection.Close();
227+
228+
//Add custom logic here if needed and remove above method.
229+
}
230+
}
231+
if (value.deleted != null && value.deleted.Count > 0)
232+
{
233+
foreach (Orders Record in (IEnumerable<Orders>)value.deleted)
234+
{
235+
//Create query to remove the specific from database by passing the primary key column value.
236+
string queryStr = $"Delete from Orders where OrderID={Record.OrderID}";
237+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
238+
SqlConnection.Open();
239+
240+
//Execute the SQL command.
241+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
242+
243+
//Execute this code to reflect the changes into the database.
244+
SqlCommand.ExecuteNonQuery();
245+
SqlConnection.Close();
246+
247+
//Add custom logic here if needed and remove above method.
248+
}
249+
}
250+
return new JsonResult(value);
251+
}
252+
public class CRUDModel<T> where T : class
253+
{
254+
public string? action { get; set; }
255+
public string? keyColumn { get; set; }
256+
public object? key { get; set; }
257+
public T? value { get; set; }
258+
public List<T>? added { get; set; }
259+
public List<T>? changed { get; set; }
260+
public List<T>? deleted { get; set; }
261+
public IDictionary<string, object>? @params { get; set; }
262+
}
263+
264+
public class Orders
265+
{
266+
[Key]
267+
public int? OrderID { get; set; }
268+
public string? CustomerID { get; set; }
269+
public int? EmployeeID { get; set; }
270+
public decimal? Freight { get; set; }
271+
public string? ShipCity { get; set; }
272+
}
273+
274+
275+
276+
277+
}
278+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace Grid_MSSQL.Server.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<SpaRoot>..\grid_mssql.client</SpaRoot>
8+
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
9+
<SpaProxyServerUrl>https://localhost:4200</SpaProxyServerUrl>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
14+
<Version>8.*-*</Version>
15+
</PackageReference>
16+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
17+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
18+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="28.2.11" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\grid_mssql.client\grid_mssql.client.esproj">
23+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
24+
</ProjectReference>
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@Grid_MSSQL.Server_HostAddress = http://localhost:5168
2+
3+
GET {{Grid_MSSQL.Server_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /