diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.sln b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.sln new file mode 100644 index 0000000..8536edc --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35818.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomAdaptor_MSSQL", "CustomAdaptor_MSSQL\CustomAdaptor_MSSQL.csproj", "{02538732-B5AE-4508-AB76-FC1D4EC8F974}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {02538732-B5AE-4508-AB76-FC1D4EC8F974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {02538732-B5AE-4508-AB76-FC1D4EC8F974}.Debug|Any CPU.Build.0 = Debug|Any CPU + {02538732-B5AE-4508-AB76-FC1D4EC8F974}.Release|Any CPU.ActiveCfg = Release|Any CPU + {02538732-B5AE-4508-AB76-FC1D4EC8F974}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C9292693-ADEC-4C4F-877A-4B7F2DF23000} + EndGlobalSection +EndGlobal diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND.MDF b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND.MDF new file mode 100644 index 0000000..4bea70d Binary files /dev/null and b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND.MDF differ diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND_log.ldf b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND_log.ldf new file mode 100644 index 0000000..0721775 Binary files /dev/null and b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/App_Data/NORTHWIND_log.ldf differ diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/GridController.cs b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/GridController.cs new file mode 100644 index 0000000..adfaa47 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/GridController.cs @@ -0,0 +1,266 @@ +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; +using System.Data; +using Syncfusion.EJ2.Base; +using Microsoft.Data.SqlClient; + +namespace CustomAdaptor_MSSQL.Server.Controllers +{ + [ApiController] + public class GridController : ControllerBase + { + string ConnectionString = @""; + + /// + /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations. + /// + /// Contains the details of the data operation requested. + /// Returns a JSON object with the filtered, sorted, and paginated data along with the total record count. + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManagerRequest DataManagerRequest) + { + // Retrieve data from the data source (e.g., database). + IQueryable DataSource = GetOrderData().AsQueryable(); + + // Initialize QueryableOperation instance. + QueryableOperation queryableOperation = new QueryableOperation(); + + // Handling searching operation. + if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search); + // Add custom logic here if needed and remove above method. + } + + // Handling filtering operation. + if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) + { + foreach (WhereFilter condition in DataManagerRequest.Where) + { + foreach (WhereFilter predicate in condition.predicates) + { + DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator); + // Add custom logic here if needed and remove above method. + } + } + } + + // Handling sorting operation. + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted); + // Add custom logic here if needed and remove above method. + } + + // Get the total count of records. + int totalRecordsCount = DataSource.Count(); + + // Handling paging operation. + if (DataManagerRequest.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip); + // Add custom logic here if needed and remove above method. + } + if (DataManagerRequest.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take); + // Add custom logic here if needed and remove above method. + } + + // Return data based on the request. + return new { result = DataSource, count = totalRecordsCount }; + } + /// + /// Retrieves the order data from the database. + /// + /// Returns a list of orders fetched from the database. + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + string queryStr = "SELECT * FROM dbo.Orders ORDER BY OrderID;"; + SqlConnection sqlConnection = new(ConnectionString); + sqlConnection.Open(); + SqlCommand sqlCommand = new(queryStr, sqlConnection); + SqlDataAdapter DataAdapter = new(sqlCommand); + DataTable DataTable = new(); + DataAdapter.Fill(DataTable); + sqlConnection.Close(); + + // Map data to a list. + List dataSource = (from DataRow Data in DataTable.Rows + select new Orders() + { + OrderID = Convert.ToInt32(Data["OrderID"]), + CustomerID = Data["CustomerID"].ToString(), + EmployeeID = Convert.IsDBNull(Data["EmployeeID"]) ? 0 : Convert.ToUInt16(Data["EmployeeID"]), + ShipCity = Data["ShipCity"].ToString(), + Freight = Convert.ToDecimal(Data["Freight"]) + } + ).ToList(); + return dataSource; + } + + /// + /// Inserts a new data item into the data collection. + /// + /// It contains the new record detail which is need to be inserted. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Insert")] + public void Insert([FromBody] CRUDModel value) + { + //Create query to insert the specific into the database by accessing its properties. + string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{value.value.CustomerID}','{value.value.Freight}','{value.value.ShipCity}','{value.value.EmployeeID}')"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + + /// + /// Update a existing data item from the data collection. + /// + /// It contains the updated record detail which is need to be updated. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Update")] + public void Update([FromBody] CRUDModel value) + { + // Create query to update the changes into the database by accessing its properties. + 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}'"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + //Add custom logic here if needed and remove above method. + } + + /// + /// Remove a specific data item from the data collection. + /// + /// It contains the specific record detail which is need to be removed. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Remove")] + public void Remove([FromBody] CRUDModel value) + { + // Create query to remove the specific from database by passing the primary key column value. + string queryStr = $"Delete from Orders where OrderID={value.key}"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + + /// + /// Batch update (Insert, Update, and Delete) a collection of data items from the data collection. + /// + /// The set of information along with details about the CRUD actions to be executed from the database. + /// Returns void. + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel value) + { + if (value.changed != null && value.changed.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.changed) + { + // Create query to update the changes into the database by accessing its properties. + string queryStr = $"Update Orders set CustomerID='{Record.CustomerID}', Freight='{Record.Freight}',EmployeeID='{Record.EmployeeID}',ShipCity='{Record.ShipCity}' where OrderID='{Record.OrderID}'"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + if (value.added != null && value.added.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.added) + { + // Create query to insert the specific into the database by accessing its properties. + string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{Record.CustomerID}','{Record.Freight}','{Record.ShipCity}','{Record.EmployeeID}')"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + if (value.deleted != null && value.deleted.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.deleted) + { + // Create query to remove the specific from database by passing the primary key column value. + string queryStr = $"Delete from Orders where OrderID={Record.OrderID}"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + return new JsonResult(value); + } + public class CRUDModel where T : class + { + public string? action { get; set; } + public string? keyColumn { get; set; } + public object? key { get; set; } + public T? value { get; set; } + public List? added { get; set; } + public List? changed { get; set; } + public List? deleted { get; set; } + public IDictionary? @params { get; set; } + } + public class Orders + { + [Key] + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public decimal? Freight { get; set; } + public string? ShipCity { get; set; } + } + } +} \ No newline at end of file diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/WeatherForecastController.cs b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..7d1af87 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace CustomAdaptor_MSSQL.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj new file mode 100644 index 0000000..4a5ec07 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + + + + + + + + + + diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj.user b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.http b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.http new file mode 100644 index 0000000..7c2d19c --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL.http @@ -0,0 +1,6 @@ +@CustomAdaptor_MSSQL_HostAddress = http://localhost:5270 + +GET {{CustomAdaptor_MSSQL_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Program.cs b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Program.cs new file mode 100644 index 0000000..8841217 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Program.cs @@ -0,0 +1,26 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.UseDefaultFiles(); +app.UseStaticFiles(); +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Properties/launchSettings.json b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Properties/launchSettings.json new file mode 100644 index 0000000..20b536a --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:47760", + "sslPort": 44392 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5270", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "https://localhost:7159;http://localhost:5270", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/WeatherForecast.cs b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/WeatherForecast.cs new file mode 100644 index 0000000..987d528 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace CustomAdaptor_MSSQL +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.Development.json b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.json b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/index.html b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/index.html new file mode 100644 index 0000000..b7ccd88 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/index.html @@ -0,0 +1,30 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/CustomAdaptor.js b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/CustomAdaptor.js new file mode 100644 index 0000000..389f023 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/CustomAdaptor.js @@ -0,0 +1,60 @@ +export class CustomAdaptor extends ej.data.UrlAdaptor { + processResponse() { + // Calling base class processResponse function. + const original = super.processResponse.apply(this, arguments); + return original; + } + + + insert(dm, data) { + return { + url: dm.dataSource.insertUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + value: data, + action: 'insert' + }), + type: 'POST' + }; + } + + update(dm, keyField, value) { + return { + url: dm.dataSource.updateUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + value: value, + action: 'update' + }), + type: 'POST' + }; + } + + remove(dm, keyField, value) { + return { + url: dm.dataSource.removeUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + key: value, + keyColumn: keyField, + action: 'remove' + }), + type: 'POST' + }; + } + + batchRequest(dm, changes, e, query, original) { + return { + url: dm.dataSource.batchUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + added: changes.addedRecords, + changed: changes.changedRecords, + deleted: changes.deletedRecords, + key: e.key, + action: 'batch' + }), + type: 'POST' + }; + } +} \ No newline at end of file diff --git a/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/index.js b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/index.js new file mode 100644 index 0000000..78f4cb2 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/CustomAdaptor_MSSQL/CustomAdaptor_MSSQL/wwwroot/js/index.js @@ -0,0 +1,32 @@ +import { CustomAdaptor } from './CustomAdaptor.js'; + +ej.grids.Grid.Inject(ej.grids.Filter, ej.grids.Sort, ej.grids.Page, ej.grids.Edit, ej.grids.Toolbar); + +let data = new ej.data.DataManager({ + url: 'https://localhost:xxxx/api/Grid', + insertUrl: 'https://localhost:xxxx/api/Grid/Insert', + updateUrl: 'https://localhost:xxxx/api/Grid/Update', + removeUrl: 'https://localhost:xxxx/api/Grid/Remove', + // Enable batch URL when batch editing is enabled. + batchUrl: 'https://localhost:xxxx/api/Grid/BatchUpdate', + adaptor: new CustomAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowGrouping: true, + allowFiltering: true, + allowSorting: true, + allowPaging: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true, isIdentity: true, type: 'number' }, + { field: 'CustomerID', headerText: 'Customer ID', validationRules: { required: true }, type: 'string', width: 100 }, + { field: 'EmployeeID', headerText: 'Employee ID', validationRules: { required: true, number: true }, width: 100 }, + { field: 'Freight', headerText: 'Freight', validationRules: { required: true, min: 1, max: 1000 }, textAlign: 'Right', width: 100 }, + { field: 'ShipCity', headerText: 'Ship City', validationRules: { required: true }, textAlign: 'Right', width: 120 } + ], + height: 348 +}); +grid.appendTo('#Grid'); \ No newline at end of file diff --git a/Binding MS SQL database using CustomAdaptor/README.md b/Binding MS SQL database using CustomAdaptor/README.md new file mode 100644 index 0000000..e5c5a68 --- /dev/null +++ b/Binding MS SQL database using CustomAdaptor/README.md @@ -0,0 +1,15 @@ +## JavaScript Grid MSSQL connectivity using CustomAdaptor + +A project that enables data binding and CRUD action handling in the Syncfusion JavaScript Grid to a MSSQL Server using CustomAdaptor feature of the Grid. + +## Steps to Run the Sample + +1. Download or unzip the project and open the project in **Visual Studio 2022**. + +2. Replace the connected database's connection string in the `GridController.cs` file. + +3. In the JavaScript client project, open `js/index.js` and replace the port number in the API URL where it says `xxxx` with the actual backend server port. + +4. Build the project to restore dependencies and compile it. + +5. Run the project. \ No newline at end of file diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL.sln b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL.sln new file mode 100644 index 0000000..8b20f48 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35818.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grid_MSSQL", "Grid_MSSQL\Grid_MSSQL.csproj", "{E85261B5-F8E1-4BD2-B4BF-4EEF009B52B7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E85261B5-F8E1-4BD2-B4BF-4EEF009B52B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E85261B5-F8E1-4BD2-B4BF-4EEF009B52B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E85261B5-F8E1-4BD2-B4BF-4EEF009B52B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E85261B5-F8E1-4BD2-B4BF-4EEF009B52B7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0DC96E47-05F7-4E9E-9F8F-CB2696E1D23E} + EndGlobalSection +EndGlobal diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND.MDF b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND.MDF new file mode 100644 index 0000000..aea5919 Binary files /dev/null and b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND.MDF differ diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND_log.ldf b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND_log.ldf new file mode 100644 index 0000000..138f7bb Binary files /dev/null and b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/App_Data/NORTHWIND_log.ldf differ diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/GridController.cs b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/GridController.cs new file mode 100644 index 0000000..ce8be8e --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/GridController.cs @@ -0,0 +1,268 @@ +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; +using System.Data; +using Syncfusion.EJ2.Base; +using Microsoft.Data.SqlClient; + +namespace Grid_MSSQL.Server.Controllers +{ + [ApiController] + public class GridController : ControllerBase + { + string ConnectionString = @""; + + /// + /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations. + /// + /// Contains the details of the data operation requested. + /// Returns a JSON object with the filtered, sorted, and paginated data along with the total record count. + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManagerRequest DataManagerRequest) + { + // Retrieve data from the data source (e.g., database). + IQueryable DataSource = GetOrderData().AsQueryable(); + + // Initialize QueryableOperation instance. + QueryableOperation queryableOperation = new QueryableOperation(); + + // Handling searching operation. + if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search); + // Add custom logic here if needed and remove above method. + } + + // Handling filtering operation. + if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) + { + foreach (WhereFilter condition in DataManagerRequest.Where) + { + foreach (WhereFilter predicate in condition.predicates) + { + DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator); + // Add custom logic here if needed and remove above method. + } + } + } + + // Handling sorting operation. + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted); + // Add custom logic here if needed and remove above method. + } + + // Get the total count of records. + int totalRecordsCount = DataSource.Count(); + + // Handling paging operation. + if (DataManagerRequest.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip); + // Add custom logic here if needed and remove above method. + } + if (DataManagerRequest.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take); + // Add custom logic here if needed and remove above method. + } + + // Return data based on the request. + return new { result = DataSource, count = totalRecordsCount }; + } + /// + /// Retrieves the order data from the database. + /// + /// Returns a list of orders fetched from the database. + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + string queryStr = "SELECT * FROM dbo.Orders ORDER BY OrderID;"; + SqlConnection sqlConnection = new(ConnectionString); + sqlConnection.Open(); + SqlCommand sqlCommand = new(queryStr, sqlConnection); + SqlDataAdapter DataAdapter = new(sqlCommand); + DataTable DataTable = new(); + DataAdapter.Fill(DataTable); + sqlConnection.Close(); + + // Map data to a list. + List dataSource = (from DataRow Data in DataTable.Rows + select new Orders() + { + OrderID = Convert.ToInt32(Data["OrderID"]), + CustomerID = Data["CustomerID"].ToString(), + EmployeeID = Convert.IsDBNull(Data["EmployeeID"]) ? 0 : Convert.ToUInt16(Data["EmployeeID"]), + ShipCity = Data["ShipCity"].ToString(), + Freight = Convert.ToDecimal(Data["Freight"]) + } + ).ToList(); + return dataSource; + } + + /// + /// Inserts a new data item into the data collection. + /// + /// It contains the new record detail which is need to be inserted. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Insert")] + public void Insert([FromBody] CRUDModel value) + { + //Create query to insert the specific into the database by accessing its properties. + string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{value.value.CustomerID}','{value.value.Freight}','{value.value.ShipCity}','{value.value.EmployeeID}')"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + + /// + /// Update a existing data item from the data collection. + /// + /// It contains the updated record detail which is need to be updated. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Update")] + public void Update([FromBody] CRUDModel value) + { + // Create query to update the changes into the database by accessing its properties. + 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}'"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + //Add custom logic here if needed and remove above method. + } + + /// + /// Remove a specific data item from the data collection. + /// + /// It contains the specific record detail which is need to be removed. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Remove")] + public void Remove([FromBody] CRUDModel value) + { + // Create query to remove the specific from database by passing the primary key column value. + string queryStr = $"Delete from Orders where OrderID={value.key}"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + + /// + /// Batch update (Insert, Update, and Delete) a collection of data items from the data collection. + /// + /// The set of information along with details about the CRUD actions to be executed from the database. + /// Returns void. + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel value) + { + if (value.changed != null && value.changed.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.changed) + { + // Create query to update the changes into the database by accessing its properties. + string queryStr = $"Update Orders set CustomerID='{Record.CustomerID}', Freight='{Record.Freight}',EmployeeID='{Record.EmployeeID}',ShipCity='{Record.ShipCity}' where OrderID='{Record.OrderID}'"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + if (value.added != null && value.added.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.added) + { + // Create query to insert the specific into the database by accessing its properties. + string queryStr = $"Insert into Orders(CustomerID,Freight,ShipCity,EmployeeID) values('{Record.CustomerID}','{Record.Freight}','{Record.ShipCity}','{Record.EmployeeID}')"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + if (value.deleted != null && value.deleted.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.deleted) + { + // Create query to remove the specific from database by passing the primary key column value. + string queryStr = $"Delete from Orders where OrderID={Record.OrderID}"; + SqlConnection SqlConnection = new SqlConnection(ConnectionString); + SqlConnection.Open(); + + // Execute the SQL command. + SqlCommand SqlCommand = new SqlCommand(queryStr, SqlConnection); + + // Execute this code to reflect the changes into the database. + SqlCommand.ExecuteNonQuery(); + SqlConnection.Close(); + + // Add custom logic here if needed and remove above method. + } + } + return new JsonResult(value); + } + + public class CRUDModel where T : class + { + public string? action { get; set; } + public string? keyColumn { get; set; } + public object? key { get; set; } + public T? value { get; set; } + public List? added { get; set; } + public List? changed { get; set; } + public List? deleted { get; set; } + public IDictionary? @params { get; set; } + } + + public class Orders + { + [Key] + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public decimal? Freight { get; set; } + public string? ShipCity { get; set; } + } + } +} \ No newline at end of file diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/WeatherForecastController.cs b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..23d8746 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Grid_MSSQL.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj new file mode 100644 index 0000000..4a5ec07 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + + + + + + + + + + diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj.user b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.http b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.http new file mode 100644 index 0000000..bfcfad2 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL.http @@ -0,0 +1,6 @@ +@Grid_MSSQL_HostAddress = http://localhost:5280 + +GET {{Grid_MSSQL_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Program.cs b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Program.cs new file mode 100644 index 0000000..8841217 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Program.cs @@ -0,0 +1,26 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.UseDefaultFiles(); +app.UseStaticFiles(); +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Properties/launchSettings.json b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Properties/launchSettings.json new file mode 100644 index 0000000..e1b598e --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57312", + "sslPort": 44378 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5280", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "https://localhost:7254;http://localhost:5280", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/WeatherForecast.cs b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/WeatherForecast.cs new file mode 100644 index 0000000..a0f3974 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Grid_MSSQL +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.Development.json b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.json b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/index.html b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/index.html new file mode 100644 index 0000000..b7ccd88 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/index.html @@ -0,0 +1,30 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/js/index.js b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/js/index.js new file mode 100644 index 0000000..45969eb --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/Grid_MSSQL/Grid_MSSQL/wwwroot/js/index.js @@ -0,0 +1,30 @@ +ej.grids.Grid.Inject(ej.grids.Filter, ej.grids.Sort, ej.grids.Page, ej.grids.Edit, ej.grids.Toolbar); + +let data = new ej.data.DataManager({ + url: 'https://localhost:xxxx/api/Grid', + insertUrl: 'https://localhost:xxxx/api/Grid/Insert', + updateUrl: 'https://localhost:xxxx/api/Grid/Update', + removeUrl: 'https://localhost:xxxx/api/Grid/Remove', + // Enable batch URL when batch editing is enabled. + batchUrl: 'https://localhost:xxxx/api/Grid/BatchUpdate', + adaptor: new ej.data.UrlAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowGrouping: true, + allowFiltering: true, + allowSorting: true, + allowPaging: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true, isIdentity: true, type: 'number' }, + { field: 'CustomerID', headerText: 'Customer ID', validationRules: { required: true }, type: 'string', width: 100 }, + { field: 'EmployeeID', headerText: 'Employee ID', validationRules: { required: true, number: true }, width: 100 }, + { field: 'Freight', headerText: 'Freight', validationRules: { required: true, min: 1, max: 1000 }, textAlign: 'Right', width: 100 }, + { field: 'ShipCity', headerText: 'Ship City', validationRules: { required: true }, textAlign: 'Right', width: 120 } + ], + height: 348 +}); +grid.appendTo('#Grid'); \ No newline at end of file diff --git a/Binding MS SQL database using UrlAdaptor/README.md b/Binding MS SQL database using UrlAdaptor/README.md new file mode 100644 index 0000000..e5c5a68 --- /dev/null +++ b/Binding MS SQL database using UrlAdaptor/README.md @@ -0,0 +1,15 @@ +## JavaScript Grid MSSQL connectivity using CustomAdaptor + +A project that enables data binding and CRUD action handling in the Syncfusion JavaScript Grid to a MSSQL Server using CustomAdaptor feature of the Grid. + +## Steps to Run the Sample + +1. Download or unzip the project and open the project in **Visual Studio 2022**. + +2. Replace the connected database's connection string in the `GridController.cs` file. + +3. In the JavaScript client project, open `js/index.js` and replace the port number in the API URL where it says `xxxx` with the actual backend server port. + +4. Build the project to restore dependencies and compile it. + +5. Run the project. \ No newline at end of file diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.sln b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.sln new file mode 100644 index 0000000..56c03d4 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35818.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomAdaptor_EntityFramework", "CustomAdaptor_EntityFramework\CustomAdaptor_EntityFramework.csproj", "{342696F3-2F20-4BE2-8D56-133AD6B47CE3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {342696F3-2F20-4BE2-8D56-133AD6B47CE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {342696F3-2F20-4BE2-8D56-133AD6B47CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {342696F3-2F20-4BE2-8D56-133AD6B47CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {342696F3-2F20-4BE2-8D56-133AD6B47CE3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8A59FFAE-EEBB-4633-AD4E-570E8B644ECF} + EndGlobalSection +EndGlobal diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND.MDF b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND.MDF new file mode 100644 index 0000000..652e635 Binary files /dev/null and b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND.MDF differ diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND_log.ldf b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND_log.ldf new file mode 100644 index 0000000..aa8da75 Binary files /dev/null and b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/App_Data/NORTHWIND_log.ldf differ diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/GridController.cs b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/GridController.cs new file mode 100644 index 0000000..377c39d --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/GridController.cs @@ -0,0 +1,262 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Data; +using Syncfusion.EJ2.Base; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace CustomAdaptor_EntityFramework.Server.Controllers +{ + [ApiController] + public class GridController : ControllerBase + { + string ConnectionString = @""; + + /// + /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations. + /// + /// Contains the details of the data operation requested. + /// Returns a JSON object with the filtered, sorted, and paginated data along with the total record count. + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManagerRequest DataManagerRequest) + { + // Retrieve data from the data source (e.g., database). + IQueryable DataSource = GetOrderData().AsQueryable(); + + // Initialize QueryableOperation instance. + QueryableOperation queryableOperation = new QueryableOperation(); + + // Handling searching operation. + if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search); + // Add custom logic here if needed and remove above method. + } + + // Handling filtering operation. + if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) + { + foreach (WhereFilter condition in DataManagerRequest.Where) + { + foreach (WhereFilter predicate in condition.predicates) + { + DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator); + // Add custom logic here if needed and remove above method. + } + } + } + + // Handling sorting operation. + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted); + // Add custom logic here if needed and remove above method. + } + + // Get the total count of records. + int totalRecordsCount = DataSource.Count(); + + // Handling paging operation. + if (DataManagerRequest.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip); + // Add custom logic here if needed and remove above method. + } + if (DataManagerRequest.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take); + // Add custom logic here if needed and remove above method. + } + + // Return data based on the request. + return new { result = DataSource, count = totalRecordsCount }; + } + + /// + /// Retrieves the order data from the database. + /// + /// Returns a list of orders fetched from the database. + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + // Retrieve orders from the orders DbSet and convert to list asynchronously. + List orders = Context.Orders.ToList(); + return orders; + } + } + + // Create a class that inherits from DbContext(Entity Framework Core). + public class OrderDbContext : DbContext + { + // Declare a private variable to store the connection string. + private readonly string _ConnectionString; + + // Define a constructor that accepts a connection string. + public OrderDbContext(string ConnectionString) + { + // Store the provided connection string. + _ConnectionString = ConnectionString; + } + + // Override the Onconfiguring method to tell EF Core to use SQL server. + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + // Use the connection string to configure the database connection. + optionsBuilder.UseSqlServer(_ConnectionString); + } + + // Define a DbSet to represent the orders table in the database. + public DbSet Orders { get; set; } + } + + /// + /// Inserts a new data item into the data collection. + /// + /// It contains the new record detail which is need to be inserted. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Insert")] + public void Insert([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + // Add the provided order to the orders DbSet. + Context.Orders.Add(value.value); + + // Save changes to the database. + Context.SaveChanges(); + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Update a existing data item from the data collection. + /// + /// It contains the updated record detail which is need to be updated. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Update")] + public void Update([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + Orders existingOrder = Context.Orders.Find(value.value.OrderID); + if (existingOrder != null) + { + // Update the existing order with the new values. + Context.Entry(existingOrder).CurrentValues.SetValues(value.value); + + // Save changes to the database. + Context.SaveChanges(); + } + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Remove a specific data item from the data collection. + /// + /// It contains the specific record detail which is need to be removed. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Remove")] + public void Remove([FromBody] CRUDModel value) + { + int OrderId = Convert.ToInt32(value.key.ToString()); + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + Orders Order = Context.Orders.Find(OrderId); + if (Order != null) + { + // Remove the order from the orders DbSet. + Context.Orders.Remove(Order); + + // Save changes to the database. + Context.SaveChanges(); + } + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Batch update (Insert, Update, and Delete) a collection of data items from the data collection. + /// + /// The set of information along with details about the CRUD actions to be executed from the database. + /// Returns void. + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + if (value.changed != null && value.changed.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.changed) + { + // Update the changed records. + Context.Orders.UpdateRange(Record); + } + } + + if (value.added != null && value.added.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.added) + { + foreach (Orders order in value.added) + { + // This ensures EF does not try to insert OrderID. + order.OrderID = default; + } + // Add new records. + Context.Orders.AddRange(value.added); + } + } + + if (value.deleted != null && value.deleted.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.deleted) + { + // Find and delete the records. + Orders ExistingOrder = Context.Orders.Find(Record.OrderID); + if (ExistingOrder != null) + { + Context.Orders.Remove(ExistingOrder); + } + } + } + + // Save changes to the database. + Context.SaveChanges(); + } + return new JsonResult(value); + } + public class CRUDModel where T : class + { + public string? action { get; set; } + public string? keyColumn { get; set; } + public object? key { get; set; } + public T? value { get; set; } + public List? added { get; set; } + public List? changed { get; set; } + public List? deleted { get; set; } + public IDictionary? @params { get; set; } + } + public class Orders + { + [Key] + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public decimal Freight { get; set; } + public string? ShipCity { get; set; } + } + } +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/WeatherForecastController.cs b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..f09f1f3 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace CustomAdaptor_EntityFramework.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj new file mode 100644 index 0000000..95381e6 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj.user b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.http b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.http new file mode 100644 index 0000000..2459c33 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework.http @@ -0,0 +1,6 @@ +@CustomAdaptor_EntityFramework_HostAddress = http://localhost:5114 + +GET {{CustomAdaptor_EntityFramework_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Program.cs b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Program.cs new file mode 100644 index 0000000..8841217 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Program.cs @@ -0,0 +1,26 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.UseDefaultFiles(); +app.UseStaticFiles(); +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Properties/launchSettings.json b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Properties/launchSettings.json new file mode 100644 index 0000000..184e341 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:46404", + "sslPort": 44316 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5114", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "https://localhost:7018;http://localhost:5114", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/WeatherForecast.cs b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/WeatherForecast.cs new file mode 100644 index 0000000..3dc2748 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace CustomAdaptor_EntityFramework +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.Development.json b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.json b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/index.html b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/index.html new file mode 100644 index 0000000..b7ccd88 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/index.html @@ -0,0 +1,30 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/CustomAdaptor.js b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/CustomAdaptor.js new file mode 100644 index 0000000..389f023 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/CustomAdaptor.js @@ -0,0 +1,60 @@ +export class CustomAdaptor extends ej.data.UrlAdaptor { + processResponse() { + // Calling base class processResponse function. + const original = super.processResponse.apply(this, arguments); + return original; + } + + + insert(dm, data) { + return { + url: dm.dataSource.insertUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + value: data, + action: 'insert' + }), + type: 'POST' + }; + } + + update(dm, keyField, value) { + return { + url: dm.dataSource.updateUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + value: value, + action: 'update' + }), + type: 'POST' + }; + } + + remove(dm, keyField, value) { + return { + url: dm.dataSource.removeUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + key: value, + keyColumn: keyField, + action: 'remove' + }), + type: 'POST' + }; + } + + batchRequest(dm, changes, e, query, original) { + return { + url: dm.dataSource.batchUrl || dm.dataSource.url, + data: JSON.stringify({ + __RequestVerificationToken: "Syncfusion", + added: changes.addedRecords, + changed: changes.changedRecords, + deleted: changes.deletedRecords, + key: e.key, + action: 'batch' + }), + type: 'POST' + }; + } +} \ No newline at end of file diff --git a/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/index.js b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/index.js new file mode 100644 index 0000000..b032f03 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/CustomAdaptor_EntityFramework/CustomAdaptor_EntityFramework/wwwroot/js/index.js @@ -0,0 +1,32 @@ +import { CustomAdaptor } from './CustomAdaptor.js'; + +ej.grids.Grid.Inject(ej.grids.Filter, ej.grids.Sort, ej.grids.Page, ej.grids.Edit, ej.grids.Toolbar); + +let data = new ej.data.DataManager({ + url: 'https://localhost:xxxx/api/Grid', + insertUrl: 'https://localhost:xxxx/api/Grid/Insert', + updateUrl: 'https://localhost:xxxx/api/Grid/Update', + removeUrl: 'https://localhost:xxxx/api/Grid/Remove', + // Enable batch URL when batch editing is enabled. + //batchUrl: 'https://localhost:xxxx/api/Grid/BatchUpdate', + adaptor: new CustomAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowGrouping: true, + allowFiltering: true, + allowSorting: true, + allowPaging: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true, isIdentity: true, type: 'number' }, + { field: 'CustomerID', headerText: 'Customer ID', validationRules: { required: true }, type: 'string', width: 100 }, + { field: 'EmployeeID', headerText: 'Employee ID', validationRules: { required: true, number: true }, width: 100 }, + { field: 'Freight', headerText: 'Freight', validationRules: { required: true, min: 1, max: 1000 }, textAlign: 'Right', width: 100 }, + { field: 'ShipCity', headerText: 'Ship City', validationRules: { required: true }, textAlign: 'Right', width: 120 } + ], + height: 348 +}); +grid.appendTo('#Grid'); \ No newline at end of file diff --git a/Binding SQL database using EF and CustomAdaptor/README.md b/Binding SQL database using EF and CustomAdaptor/README.md new file mode 100644 index 0000000..b525522 --- /dev/null +++ b/Binding SQL database using EF and CustomAdaptor/README.md @@ -0,0 +1,15 @@ +## JavaScript Grid SQL Server connectivity using Entity Framework and CustomAdaptor + +A project that enables data binding and CRUD action handling in the Syncfusion JavaScript Grid to a SQL Server using Entity Framework and CustomAdaptor feature of the Grid. + +## Steps to Run the Sample + +1. Download or unzip the project and open the project in **Visual Studio 2022**. + +2. Replace the connected database's connection string in the `GridController.cs` file. + +3. In the JavaScript client project, open `js/index.js` and replace the port number in the API URL where it says `xxxx` with the actual backend server port. + +4. Build the project to restore dependencies and compile it. + +5. Run the project. \ No newline at end of file diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework.sln b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework.sln new file mode 100644 index 0000000..9051e5f --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35818.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grid_EntityFramework", "Grid_EntityFramework\Grid_EntityFramework.csproj", "{36C6B303-7A47-47EE-9D01-3A179574DEC2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36C6B303-7A47-47EE-9D01-3A179574DEC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36C6B303-7A47-47EE-9D01-3A179574DEC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36C6B303-7A47-47EE-9D01-3A179574DEC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36C6B303-7A47-47EE-9D01-3A179574DEC2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BCC1C6E6-E805-4D83-8BAC-444DE4EAC6ED} + EndGlobalSection +EndGlobal diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND.MDF b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND.MDF new file mode 100644 index 0000000..c4220de Binary files /dev/null and b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND.MDF differ diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND_log.ldf b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND_log.ldf new file mode 100644 index 0000000..5a06cd4 Binary files /dev/null and b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/App_Data/NORTHWIND_log.ldf differ diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/GridController.cs b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/GridController.cs new file mode 100644 index 0000000..4b5da73 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/GridController.cs @@ -0,0 +1,264 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Data; +using Syncfusion.EJ2.Base; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace Grid_EntityFramework.Server.Controllers +{ + [ApiController] + public class GridController : ControllerBase + { + string ConnectionString = @""; + + /// + /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations. + /// + /// Contains the details of the data operation requested. + /// Returns a JSON object with the filtered, sorted, and paginated data along with the total record count. + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManagerRequest DataManagerRequest) + { + // Retrieve data from the data source (e.g., database). + IQueryable DataSource = GetOrderData().AsQueryable(); + + // Initialize QueryableOperation instance. + QueryableOperation queryableOperation = new QueryableOperation(); + + // Handling searching operation. + if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search); + // Add custom logic here if needed and remove above method. + } + + // Handling filtering operation. + if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) + { + foreach (WhereFilter condition in DataManagerRequest.Where) + { + foreach (WhereFilter predicate in condition.predicates) + { + DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator); + // Add custom logic here if needed and remove above method. + } + } + } + + // Handling sorting operation. + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted); + // Add custom logic here if needed and remove above method. + } + + // Get the total count of records. + int totalRecordsCount = DataSource.Count(); + + // Handling paging operation. + if (DataManagerRequest.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip); + // Add custom logic here if needed and remove above method. + } + if (DataManagerRequest.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take); + // Add custom logic here if needed and remove above method. + } + + // Return data based on the request. + return new { result = DataSource, count = totalRecordsCount }; + } + + /// + /// Retrieves the order data from the database. + /// + /// Returns a list of orders fetched from the database. + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + // Retrieve orders from the orders DbSet and convert to list asynchronously. + List orders = Context.Orders.ToList(); + return orders; + } + } + + // Create a class that inherits from DbContext(Entity Framework Core). + public class OrderDbContext : DbContext + { + // Declare a private variable to store the connection string. + private readonly string _ConnectionString; + + // Define a constructor that accepts a connection string. + public OrderDbContext(string ConnectionString) + { + // Store the provided connection string. + _ConnectionString = ConnectionString; + } + + // Override the Onconfiguring method to tell EF Core to use SQL server. + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + // Use the connection string to configure the database connection. + optionsBuilder.UseSqlServer(_ConnectionString); + } + + // Define a DbSet to represent the orders table in the database. + public DbSet Orders { get; set; } + } + + /// + /// Inserts a new data item into the data collection. + /// + /// It contains the new record detail which is need to be inserted. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Insert")] + public void Insert([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + // Add the provided order to the orders DbSet. + Context.Orders.Add(value.value); + + // Save changes to the database. + Context.SaveChanges(); + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Update a existing data item from the data collection. + /// + /// It contains the updated record detail which is need to be updated. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Update")] + public void Update([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + Orders existingOrder = Context.Orders.Find(value.value.OrderID); + if (existingOrder != null) + { + // Update the existing order with the new values. + Context.Entry(existingOrder).CurrentValues.SetValues(value.value); + + // Save changes to the database. + Context.SaveChanges(); + } + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Remove a specific data item from the data collection. + /// + /// It contains the specific record detail which is need to be removed. + /// Returns void. + [HttpPost] + [Route("api/[controller]/Remove")] + public void Remove([FromBody] CRUDModel value) + { + int OrderId = Convert.ToInt32(value.key.ToString()); + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + Orders Order = Context.Orders.Find(OrderId); + if (Order != null) + { + // Remove the order from the orders DbSet. + Context.Orders.Remove(Order); + + // Save changes to the database. + Context.SaveChanges(); + } + } + + // Add custom logic here if needed and remove above method. + } + + /// + /// Batch update (Insert, Update, and Delete) a collection of data items from the data collection. + /// + /// The set of information along with details about the CRUD actions to be executed from the database. + /// Returns void. + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel value) + { + using (OrderDbContext Context = new OrderDbContext(ConnectionString)) + { + if (value.changed != null && value.changed.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.changed) + { + // Update the changed records. + Context.Orders.UpdateRange(Record); + } + } + + if (value.added != null && value.added.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.added) + { + foreach (Orders order in value.added) + { + // This ensures EF does not try to insert OrderID. + order.OrderID = default; + } + // Add new records. + Context.Orders.AddRange(value.added); + } + } + + if (value.deleted != null && value.deleted.Count > 0) + { + foreach (Orders Record in (IEnumerable)value.deleted) + { + // Find and delete the records. + Orders ExistingOrder = Context.Orders.Find(Record.OrderID); + if (ExistingOrder != null) + { + Context.Orders.Remove(ExistingOrder); + } + } + } + + // Save changes to the database. + Context.SaveChanges(); + } + return new JsonResult(value); + } + + public class CRUDModel where T : class + { + public string? action { get; set; } + public string? keyColumn { get; set; } + public object? key { get; set; } + public T? value { get; set; } + public List? added { get; set; } + public List? changed { get; set; } + public List? deleted { get; set; } + public IDictionary? @params { get; set; } + } + + public class Orders + { + [Key] + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public decimal Freight { get; set; } + public string? ShipCity { get; set; } + } + } +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/WeatherForecastController.cs b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..9a05768 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Grid_EntityFramework.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj new file mode 100644 index 0000000..95381e6 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj.user b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.http b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.http new file mode 100644 index 0000000..5784bc9 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Grid_EntityFramework.http @@ -0,0 +1,6 @@ +@Grid_EntityFramework_HostAddress = http://localhost:5137 + +GET {{Grid_EntityFramework_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Program.cs b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Program.cs new file mode 100644 index 0000000..8841217 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Program.cs @@ -0,0 +1,26 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.UseDefaultFiles(); +app.UseStaticFiles(); +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Properties/launchSettings.json b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Properties/launchSettings.json new file mode 100644 index 0000000..7242ae2 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:2062", + "sslPort": 44360 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5137", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "https://localhost:7238;http://localhost:5137", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/WeatherForecast.cs b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/WeatherForecast.cs new file mode 100644 index 0000000..11fd463 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Grid_EntityFramework +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.Development.json b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.json b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/index.html b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/index.html new file mode 100644 index 0000000..b7ccd88 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/index.html @@ -0,0 +1,30 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/js/index.js b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/js/index.js new file mode 100644 index 0000000..3d9ab57 --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/Grid_EntityFramework/Grid_EntityFramework/wwwroot/js/index.js @@ -0,0 +1,30 @@ +ej.grids.Grid.Inject(ej.grids.Filter, ej.grids.Sort, ej.grids.Page, ej.grids.Edit, ej.grids.Toolbar); + +let data = new ej.data.DataManager({ + url: 'https://localhost:xxxx/api/Grid', + insertUrl: 'https://localhost:xxxx/api/Grid/Insert', + updateUrl: 'https://localhost:xxxx/api/Grid/Update', + removeUrl: 'https://localhost:xxxx/api/Grid/Remove', + // Enable batch URL when batch editing is enabled. + //batchUrl: 'https://localhost:xxxx/api/Grid/BatchUpdate', + adaptor: new ej.data.UrlAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowGrouping: true, + allowFiltering: true, + allowSorting: true, + allowPaging: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true, isIdentity: true, type: 'number' }, + { field: 'CustomerID', headerText: 'Customer ID', validationRules: { required: true }, type: 'string', width: 100 }, + { field: 'EmployeeID', headerText: 'Employee ID', validationRules: { required: true, number: true }, width: 100 }, + { field: 'Freight', headerText: 'Freight', validationRules: { required: true, min: 1, max: 1000 }, textAlign: 'Right', width: 100 }, + { field: 'ShipCity', headerText: 'Ship City', validationRules: { required: true }, textAlign: 'Right', width: 120 } + ], + height: 348 +}); +grid.appendTo('#Grid'); \ No newline at end of file diff --git a/Binding SQL database using EF and UrlAdaptor/README.md b/Binding SQL database using EF and UrlAdaptor/README.md new file mode 100644 index 0000000..d6ac9cc --- /dev/null +++ b/Binding SQL database using EF and UrlAdaptor/README.md @@ -0,0 +1,15 @@ +## JavaScript Grid SQL Server connectivity using Entity Framework and UrlAdaptor + +A project that enables data binding and CRUD action handling in the Syncfusion JavaScript Grid to a SQL Server using Entity Framework and UrlAdaptor feature of the Grid. + +## Steps to Run the Sample + +1. Download or unzip the project and open the project in **Visual Studio 2022**. + +2. Replace the connected database's connection string in the `GridController.cs` file. + +3. In the JavaScript client project, open `js/index.js` and replace the port number in the API URL where it says `xxxx` with the actual backend server port. + +4. Build the project to restore dependencies and compile it. + +5. Run the project. \ No newline at end of file diff --git a/README.md b/README.md index 0326317..e39eaf6 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,5 @@ Here, we have explained in detail how to bind the listed databases below to the 2. MYSQL Database 3. PostgreSQL Database 4. Dapper -5. SQLite \ No newline at end of file +5. SQLite +6. Entity Framework \ No newline at end of file