Skip to content

Commit 8dd9c9a

Browse files
Updated sample.
1 parent 76d9631 commit 8dd9c9a

File tree

317 files changed

+12736
-5
lines changed

Some content is hidden

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

317 files changed

+12736
-5
lines changed

Binding Dapper using CustomAdaptor/Grid_Dapper_CustomAdaptor/.vs/Grid_Dapper_CustomAdaptor/config/applicationhost.config

Lines changed: 1011 additions & 0 deletions
Large diffs are not rendered by default.

Binding Dapper using CustomAdaptor/Grid_Dapper_CustomAdaptor/.vs/Grid_Dapper_CustomAdaptor/v17/DocumentLayout.backup.json

Lines changed: 235 additions & 0 deletions
Large diffs are not rendered by default.

Binding Dapper using CustomAdaptor/Grid_Dapper_CustomAdaptor/.vs/Grid_Dapper_CustomAdaptor/v17/DocumentLayout.json

Lines changed: 235 additions & 0 deletions
Large diffs are not rendered by default.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.ComponentModel.DataAnnotations;
3+
using System.Data;
4+
using Microsoft.Data.SqlClient;
5+
using Syncfusion.EJ2.Base;
6+
using Dapper;
7+
8+
namespace Grid_Dapper_CustomAdaptor.Server.Controllers
9+
{
10+
[ApiController]
11+
public class GridController : ControllerBase
12+
{
13+
string ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\asp.core\Binding-data-from-remote-service-to-angular-data-grid\UrlAdaptor\UrlAdaptor.Server\App_Data\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=True";
14+
15+
/// <summary>
16+
/// Processes the DataManager request to perform searching, filtering, sorting, and paging operations.
17+
/// </summary>
18+
/// <param name="DataManagerRequest">Contains the details of the data operation requested.</param>
19+
/// <returns>Returns a JSON object with the filtered, sorted, and paginated data along with the total record count.</returns>
20+
[HttpPost]
21+
[Route("api/[controller]")]
22+
public object Post([FromBody] DataManagerRequest DataManagerRequest)
23+
{
24+
// Retrieve data from the data source (e.g., database).
25+
IQueryable<Orders> DataSource = GetOrderData().AsQueryable();
26+
27+
// Initialize QueryableOperation instance.
28+
QueryableOperation queryableOperation = new QueryableOperation();
29+
30+
// Handling searching operation.
31+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
32+
{
33+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
34+
//Add custom logic here if needed and remove above method.
35+
}
36+
37+
// Handling filtering operation.
38+
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
39+
{
40+
foreach (WhereFilter condition in DataManagerRequest.Where)
41+
{
42+
foreach (WhereFilter predicate in condition.predicates)
43+
{
44+
DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator);
45+
//Add custom logic here if needed and remove above method.
46+
}
47+
}
48+
}
49+
50+
// Handling sorting operation.
51+
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
52+
{
53+
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
54+
//Add custom logic here if needed and remove above method.s
55+
}
56+
57+
58+
// Get the total count of records.
59+
int totalRecordsCount = DataSource.Count();
60+
61+
// Handling paging operation.
62+
if (DataManagerRequest.Skip != 0)
63+
{
64+
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
65+
//Add custom logic here if needed and remove above method.
66+
}
67+
if (DataManagerRequest.Take != 0)
68+
{
69+
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
70+
//Add custom logic here if needed and remove above method.
71+
}
72+
73+
// Return data based on the request.
74+
return new { result = DataSource, count = totalRecordsCount };
75+
}
76+
77+
/// <summary>
78+
/// Retrieves the order data from the database.
79+
/// </summary>
80+
/// <returns>Returns a list of orders fetched from the database.</returns>
81+
[HttpGet]
82+
[Route("api/[controller]")]
83+
public List<Orders> GetOrderData()
84+
{
85+
string queryStr = "SELECT * FROM dbo.Orders ORDER BY OrderID;";
86+
87+
//Create SQL connection.
88+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
89+
{
90+
Connection.Open();
91+
// Dapper automatically handles mapping to your Order class.
92+
List<Orders> orders = Connection.Query<Orders>(queryStr).ToList();
93+
return orders;
94+
}
95+
}
96+
97+
/// <summary>
98+
/// Inserts a new data item into the data collection.
99+
/// </summary>
100+
/// <param name="value">It contains the new record detail which is need to be inserted.</param>
101+
/// <returns>Returns void.</returns>
102+
[HttpPost]
103+
[Route("api/[controller]/Insert")]
104+
public void Insert([FromBody] CRUDModel<Orders> value)
105+
{
106+
//Create query to insert the specific into the database by accessing its properties.
107+
string queryStr = "INSERT INTO Orders(CustomerID, Freight, ShipCity, EmployeeID) VALUES(@CustomerID, @Freight, @ShipCity, @EmployeeID)";
108+
109+
//Create SQL connection.
110+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
111+
{
112+
Connection.Open();
113+
//Execute this code to reflect the changes into the database.
114+
Connection.Execute(queryStr, value.value);
115+
}
116+
117+
//Add custom logic here if needed and remove above method.
118+
}
119+
120+
/// <summary>
121+
/// Update a existing data item from the data collection.
122+
/// </summary>
123+
/// <param name="value">It contains the updated record detail which is need to be updated.</param>
124+
/// <returns>Returns void.</returns>
125+
[HttpPost]
126+
[Route("api/[controller]/Update")]
127+
public void Update([FromBody] CRUDModel<Orders> value)
128+
{
129+
//Create query to update the changes into the database by accessing its properties.
130+
string queryStr = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID";
131+
132+
//Create SQL connection.
133+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
134+
{
135+
Connection.Open();
136+
//Execute this code to reflect the changes into the database.
137+
Connection.Execute(queryStr, value.value);
138+
}
139+
140+
//Add custom logic here if needed and remove above method.
141+
}
142+
143+
/// <summary>
144+
/// Remove a specific data item from the data collection.
145+
/// </summary>
146+
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
147+
/// <return>Returns void.</return>
148+
[HttpPost]
149+
[Route("api/[controller]/Remove")]
150+
public void Remove([FromBody] CRUDModel<Orders> value)
151+
{
152+
//Create query to remove the specific from database by passing the primary key column value.
153+
string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID";
154+
155+
//Create SQL connection.
156+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
157+
{
158+
Connection.Open();
159+
int orderID = Convert.ToInt32(value.key.ToString());
160+
//Execute this code to reflect the changes into the database.
161+
Connection.Execute(queryStr, new { OrderID = orderID });
162+
}
163+
164+
//Add custom logic here if needed and remove above method.
165+
}
166+
167+
168+
/// <summary>
169+
/// Batch update (Insert, Update, and Delete) a collection of data items from the data collection.
170+
/// </summary>
171+
/// <param name="value">The set of information along with details about the CRUD actions to be executed from the database.</param>
172+
/// <returns>Returns void.</returns>
173+
[HttpPost]
174+
[Route("api/[controller]/BatchUpdate")]
175+
public IActionResult BatchUpdate([FromBody] CRUDModel<Orders> value)
176+
{
177+
if (value.changed != null && value.changed.Count > 0)
178+
{
179+
foreach (Orders Record in (IEnumerable<Orders>)value.changed)
180+
{
181+
//Create query to update the changes into the database by accessing its properties.
182+
string queryStr = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID";
183+
184+
//Create SQL connection.
185+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
186+
{
187+
Connection.Open();
188+
//Execute this code to reflect the changes into the database.
189+
Connection.Execute(queryStr, Record);
190+
}
191+
192+
//Add custom logic here if needed and remove above method.
193+
}
194+
}
195+
if (value.added != null && value.added.Count > 0)
196+
{
197+
foreach (Orders Record in (IEnumerable<Orders>)value.added)
198+
{
199+
//Create query to insert the specific into the database by accessing its properties.
200+
string queryStr = "INSERT INTO Orders (CustomerID, Freight, ShipCity, EmployeeID) VALUES (@CustomerID, @Freight, @ShipCity, @EmployeeID)";
201+
202+
//Create SQL connection.
203+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
204+
{
205+
Connection.Open();
206+
//Execute this code to reflect the changes into the database.
207+
Connection.Execute(queryStr, Record);
208+
}
209+
210+
//Add custom logic here if needed and remove above method.
211+
}
212+
}
213+
if (value.deleted != null && value.deleted.Count > 0)
214+
{
215+
foreach (Orders Record in (IEnumerable<Orders>)value.deleted)
216+
{
217+
//Create query to remove the specific from database by passing the primary key column value.
218+
string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID";
219+
220+
//Create SQL connection.
221+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
222+
{
223+
Connection.Open();
224+
//Execute this code to reflect the changes into the database.
225+
Connection.Execute(queryStr, new { OrderID = Record.OrderID });
226+
}
227+
228+
//Add custom logic here if needed and remove above method.
229+
}
230+
}
231+
return new JsonResult(value);
232+
}
233+
234+
public class Orders
235+
{
236+
[Key]
237+
public int? OrderID { get; set; }
238+
public string? CustomerID { get; set; }
239+
public int? EmployeeID { get; set; }
240+
public decimal? Freight { get; set; }
241+
public string? ShipCity { get; set; }
242+
}
243+
244+
public class CRUDModel<T> where T : class
245+
{
246+
public string? action { get; set; }
247+
public string? keyColumn { get; set; }
248+
public object? key { get; set; }
249+
public T? value { get; set; }
250+
public List<T>? added { get; set; }
251+
public List<T>? changed { get; set; }
252+
public List<T>? deleted { get; set; }
253+
public IDictionary<string, object>? @params { get; set; }
254+
}
255+
}
256+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace Grid_Dapper_CustomAdaptor.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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_dapper_customadaptor.client</SpaRoot>
8+
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
9+
<SpaProxyServerUrl>https://localhost:4200</SpaProxyServerUrl>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Dapper" Version="2.1.66" />
14+
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
15+
<Version>8.*-*</Version>
16+
</PackageReference>
17+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
19+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="28.2.11" />
20+
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\grid_dapper_customadaptor.client\grid_dapper_customadaptor.client.esproj">
25+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
26+
</ProjectReference>
27+
</ItemGroup>
28+
29+
</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+
@Grid_Dapper_CustomAdaptor.Server_HostAddress = http://localhost:5266
2+
3+
GET {{Grid_Dapper_CustomAdaptor.Server_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers().AddJsonOptions(options =>
6+
{
7+
options.JsonSerializerOptions.PropertyNamingPolicy = null; // Use PascalCase
8+
});
9+
builder.Services.AddControllers();
10+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
11+
builder.Services.AddEndpointsApiExplorer();
12+
builder.Services.AddSwaggerGen();
13+
14+
builder.Services.AddCors(options =>
15+
{
16+
options.AddDefaultPolicy(builder =>
17+
{
18+
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
19+
});
20+
});
21+
var app = builder.Build();
22+
app.UseCors();
23+
24+
app.UseDefaultFiles();
25+
app.UseStaticFiles();
26+
27+
// Configure the HTTP request pipeline.
28+
if (app.Environment.IsDevelopment())
29+
{
30+
app.UseSwagger();
31+
app.UseSwaggerUI();
32+
}
33+
34+
app.UseHttpsRedirection();
35+
36+
app.UseAuthorization();
37+
38+
app.MapControllers();
39+
40+
app.MapFallbackToFile("/index.html");
41+
42+
app.Run();

0 commit comments

Comments
 (0)