Skip to content

Commit a6b3d4d

Browse files
Updated GitHub Sample.
1 parent 7d5f905 commit a6b3d4d

File tree

66 files changed

+2210
-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.

66 files changed

+2210
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.13.35818.85
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomAdaptor_MSSQL", "CustomAdaptor_MSSQL\CustomAdaptor_MSSQL.csproj", "{02538732-B5AE-4508-AB76-FC1D4EC8F974}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{02538732-B5AE-4508-AB76-FC1D4EC8F974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{02538732-B5AE-4508-AB76-FC1D4EC8F974}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{02538732-B5AE-4508-AB76-FC1D4EC8F974}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{02538732-B5AE-4508-AB76-FC1D4EC8F974}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {C9292693-ADEC-4C4F-877A-4B7F2DF23000}
23+
EndGlobalSection
24+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
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 CustomAdaptor_MSSQL.Server.Controllers
8+
{
9+
[ApiController]
10+
public class GridController : ControllerBase
11+
{
12+
string ConnectionString = @"<Enter a valid connection string>";
13+
14+
/// <summary>
15+
/// Processes the DataManager request to perform searching, filtering, sorting, and paging operations.
16+
/// </summary>
17+
/// <param name="DataManagerRequest">Contains the details of the data operation requested.</param>
18+
/// <returns>Returns a JSON object with the filtered, sorted, and paginated data along with the total record count.</returns>
19+
[HttpPost]
20+
[Route("api/[controller]")]
21+
public object Post([FromBody] DataManagerRequest DataManagerRequest)
22+
{
23+
// Retrieve data from the data source (e.g., database).
24+
IQueryable<Orders> DataSource = GetOrderData().AsQueryable();
25+
26+
// Initialize QueryableOperation instance.
27+
QueryableOperation queryableOperation = new QueryableOperation();
28+
29+
// Handling searching operation.
30+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
31+
{
32+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
33+
// Add custom logic here if needed and remove above method.
34+
}
35+
36+
// Handling filtering operation.
37+
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
38+
{
39+
foreach (WhereFilter condition in DataManagerRequest.Where)
40+
{
41+
foreach (WhereFilter predicate in condition.predicates)
42+
{
43+
DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator);
44+
// Add custom logic here if needed and remove above method.
45+
}
46+
}
47+
}
48+
49+
// Handling sorting operation.
50+
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
51+
{
52+
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
53+
// Add custom logic here if needed and remove above method.
54+
}
55+
56+
// Get the total count of records.
57+
int totalRecordsCount = DataSource.Count();
58+
59+
// Handling paging operation.
60+
if (DataManagerRequest.Skip != 0)
61+
{
62+
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
63+
// Add custom logic here if needed and remove above method.
64+
}
65+
if (DataManagerRequest.Take != 0)
66+
{
67+
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
68+
// Add custom logic here if needed and remove above method.
69+
}
70+
71+
// Return data based on the request.
72+
return new { result = DataSource, count = totalRecordsCount };
73+
}
74+
/// <summary>
75+
/// Retrieves the order data from the database.
76+
/// </summary>
77+
/// <returns>Returns a list of orders fetched from the database.</returns>
78+
[HttpGet]
79+
[Route("api/[controller]")]
80+
public List<Orders> GetOrderData()
81+
{
82+
string queryStr = "SELECT * FROM dbo.Orders ORDER BY OrderID;";
83+
SqlConnection sqlConnection = new(ConnectionString);
84+
sqlConnection.Open();
85+
SqlCommand sqlCommand = new(queryStr, sqlConnection);
86+
SqlDataAdapter DataAdapter = new(sqlCommand);
87+
DataTable DataTable = new();
88+
DataAdapter.Fill(DataTable);
89+
sqlConnection.Close();
90+
91+
// Map data to a list.
92+
List<Orders> dataSource = (from DataRow Data in DataTable.Rows
93+
select new Orders()
94+
{
95+
OrderID = Convert.ToInt32(Data["OrderID"]),
96+
CustomerID = Data["CustomerID"].ToString(),
97+
EmployeeID = Convert.IsDBNull(Data["EmployeeID"]) ? 0 : Convert.ToUInt16(Data["EmployeeID"]),
98+
ShipCity = Data["ShipCity"].ToString(),
99+
Freight = Convert.ToDecimal(Data["Freight"])
100+
}
101+
).ToList();
102+
return dataSource;
103+
}
104+
105+
/// <summary>
106+
/// Inserts a new data item into the data collection.
107+
/// </summary>
108+
/// <param name="value">It contains the new record detail which is need to be inserted.</param>
109+
/// <returns>Returns void.</returns>
110+
[HttpPost]
111+
[Route("api/[controller]/Insert")]
112+
public void Insert([FromBody] CRUDModel<Orders> value)
113+
{
114+
//Create query to insert the specific into the database by accessing its properties.
115+
string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{value.value.CustomerID}','{value.value.Freight}','{value.value.ShipCity}','{value.value.EmployeeID}')";
116+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
117+
SqlConnection.Open();
118+
119+
// Execute the SQL command.
120+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
121+
122+
// Execute this code to reflect the changes into the database.
123+
SqlCommand.ExecuteNonQuery();
124+
SqlConnection.Close();
125+
126+
// Add custom logic here if needed and remove above method.
127+
}
128+
129+
/// <summary>
130+
/// Update a existing data item from the data collection.
131+
/// </summary>
132+
/// <param name="value">It contains the updated record detail which is need to be updated.</param>
133+
/// <returns>Returns void.</returns>
134+
[HttpPost]
135+
[Route("api/[controller]/Update")]
136+
public void Update([FromBody] CRUDModel<Orders> value)
137+
{
138+
// Create query to update the changes into the database by accessing its properties.
139+
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}'";
140+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
141+
SqlConnection.Open();
142+
143+
// Execute the SQL command.
144+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
145+
146+
// Execute this code to reflect the changes into the database.
147+
SqlCommand.ExecuteNonQuery();
148+
SqlConnection.Close();
149+
150+
//Add custom logic here if needed and remove above method.
151+
}
152+
153+
/// <summary>
154+
/// Remove a specific data item from the data collection.
155+
/// </summary>
156+
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
157+
/// <return>Returns void.</return>
158+
[HttpPost]
159+
[Route("api/[controller]/Remove")]
160+
public void Remove([FromBody] CRUDModel<Orders> value)
161+
{
162+
// Create query to remove the specific from database by passing the primary key column value.
163+
string queryStr = $"Delete from Orders where OrderID={value.key}";
164+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
165+
SqlConnection.Open();
166+
167+
// Execute the SQL command.
168+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
169+
170+
// Execute this code to reflect the changes into the database.
171+
SqlCommand.ExecuteNonQuery();
172+
SqlConnection.Close();
173+
174+
// Add custom logic here if needed and remove above method.
175+
}
176+
177+
/// <summary>
178+
/// Batch update (Insert, Update, and Delete) a collection of data items from the data collection.
179+
/// </summary>
180+
/// <param name="CRUDModel<T>">The set of information along with details about the CRUD actions to be executed from the database.</param>
181+
/// <returns>Returns void.</returns>
182+
[HttpPost]
183+
[Route("api/[controller]/BatchUpdate")]
184+
public IActionResult BatchUpdate([FromBody] CRUDModel<Orders> value)
185+
{
186+
if (value.changed != null && value.changed.Count > 0)
187+
{
188+
foreach (Orders Record in (IEnumerable<Orders>)value.changed)
189+
{
190+
// Create query to update the changes into the database by accessing its properties.
191+
string queryStr = $"Update Orders set CustomerID='{Record.CustomerID}', Freight='{Record.Freight}',EmployeeID='{Record.EmployeeID}',ShipCity='{Record.ShipCity}' where OrderID='{Record.OrderID}'";
192+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
193+
SqlConnection.Open();
194+
195+
// Execute the SQL command.
196+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
197+
198+
// Execute this code to reflect the changes into the database.
199+
SqlCommand.ExecuteNonQuery();
200+
SqlConnection.Close();
201+
202+
// Add custom logic here if needed and remove above method.
203+
}
204+
}
205+
if (value.added != null && value.added.Count > 0)
206+
{
207+
foreach (Orders Record in (IEnumerable<Orders>)value.added)
208+
{
209+
// Create query to insert the specific into the database by accessing its properties.
210+
string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{Record.CustomerID}','{Record.Freight}','{Record.ShipCity}','{Record.EmployeeID}')";
211+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
212+
SqlConnection.Open();
213+
214+
// Execute the SQL command.
215+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
216+
217+
// Execute this code to reflect the changes into the database.
218+
SqlCommand.ExecuteNonQuery();
219+
SqlConnection.Close();
220+
221+
// Add custom logic here if needed and remove above method.
222+
}
223+
}
224+
if (value.deleted != null && value.deleted.Count > 0)
225+
{
226+
foreach (Orders Record in (IEnumerable<Orders>)value.deleted)
227+
{
228+
// Create query to remove the specific from database by passing the primary key column value.
229+
string queryStr = $"Delete from Orders where OrderID={Record.OrderID}";
230+
SqlConnection SqlConnection = new SqlConnection(ConnectionString);
231+
SqlConnection.Open();
232+
233+
// Execute the SQL command.
234+
SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection);
235+
236+
// Execute this code to reflect the changes into the database.
237+
SqlCommand.ExecuteNonQuery();
238+
SqlConnection.Close();
239+
240+
// Add custom logic here if needed and remove above method.
241+
}
242+
}
243+
return new JsonResult(value);
244+
}
245+
public class CRUDModel<T> where T : class
246+
{
247+
public string? action { get; set; }
248+
public string? keyColumn { get; set; }
249+
public object? key { get; set; }
250+
public T? value { get; set; }
251+
public List<T>? added { get; set; }
252+
public List<T>? changed { get; set; }
253+
public List<T>? deleted { get; set; }
254+
public IDictionary<string, object>? @params { get; set; }
255+
}
256+
public class Orders
257+
{
258+
[Key]
259+
public int? OrderID { get; set; }
260+
public string? CustomerID { get; set; }
261+
public int? EmployeeID { get; set; }
262+
public decimal? Freight { get; set; }
263+
public string? ShipCity { get; set; }
264+
}
265+
}
266+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace CustomAdaptor_MSSQL.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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
12+
<PackageReference Include="Syncfusion.EJ" Version="20.4.0.44" />
13+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="29.1.35" />
14+
</ItemGroup>
15+
16+
</Project>
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@CustomAdaptor_MSSQL_HostAddress = http://localhost:5270
2+
3+
GET {{CustomAdaptor_MSSQL_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
app.UseDefaultFiles();
19+
app.UseStaticFiles();
20+
app.UseHttpsRedirection();
21+
22+
app.UseAuthorization();
23+
24+
app.MapControllers();
25+
26+
app.Run();

0 commit comments

Comments
 (0)