diff --git a/UrlAdaptor/UrlAdaptor.sln b/UrlAdaptor/UrlAdaptor.sln new file mode 100644 index 0000000..5d5710c --- /dev/null +++ b/UrlAdaptor/UrlAdaptor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UrlAdaptor", "UrlAdaptor\UrlAdaptor.csproj", "{360C4474-3D1D-403C-9978-53F638BD7FAB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3164F0E4-6B1E-4342-8E30-A08AA69AE150} + EndGlobalSection +EndGlobal diff --git a/UrlAdaptor/UrlAdaptor/Controllers/GridController.cs b/UrlAdaptor/UrlAdaptor/Controllers/GridController.cs new file mode 100644 index 0000000..98cbd2c --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/Controllers/GridController.cs @@ -0,0 +1,224 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Syncfusion.EJ2.Base; +using UrlAdaptor.Models; + +namespace UrlAdaptor.Controllers +{ + [ApiController] + public class GridController : Controller + { + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManagerRequest DataManagerRequest) + { + // Retrieve data from the data source (e.g., database) + IQueryable DataSource = GetOrderData().AsQueryable(); + + QueryableOperation queryableOperation = new QueryableOperation(); // Initialize DataOperations instance + + // Handling searching operation + if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search); + } + + // Handling filtering operation + if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) + { + foreach (var condition in DataManagerRequest.Where) + { + foreach (var predicate in condition.predicates) + { + DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator); + } + } + } + + // Handling sorting operation + if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted); + } + + // Get the total count of records + int totalRecordsCount = DataSource.Count(); + + // Handling paging operation. + if (DataManagerRequest.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip); + } + if (DataManagerRequest.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take); + } + + // Return data based on the request + return new { result = DataSource, count = totalRecordsCount }; + } + + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + var data = OrdersDetails.GetAllRecords().ToList(); + return data; + } + + /// + /// 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/Grid/Insert")] + public void Insert([FromBody] CRUDModel newRecord) + { + if (newRecord.value != null) + { + OrdersDetails.GetAllRecords().Insert(0, newRecord.value); + } + } + + /// + /// 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/Grid/Update")] + public void Update([FromBody] CRUDModel Order) + { + var updatedOrder = Order.value; + if (updatedOrder != null) + { + var data = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == updatedOrder.OrderID); + if (data != null) + { + // Update the existing record + data.OrderID = updatedOrder.OrderID; + data.CustomerID = updatedOrder.CustomerID; + data.ShipCity = updatedOrder.ShipCity; + data.ShipCountry = updatedOrder.ShipCountry; + // Update other properties similarly + } + } + + } + /// + /// 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/Grid/Remove")] + public void Remove([FromBody] CRUDModel value) + { + int orderId = int.Parse((value.key).ToString()); + var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId); + if (data != null) + { + // Remove the record from the data collection + OrdersDetails.GetAllRecords().Remove(data); + } + } + + /// + /// Perform all the CRUD operation at server-side using a single method instead of specifying separate controller action method for CRUD (insert, update and delete) operations. + /// + /// + [HttpPost] + [Route("api/[controller]/CrudUpdate")] + public void CrudUpdate([FromBody] CRUDModel request) + { + if (request.action == "update") + { + // Update record + var orderValue = request.value; + OrdersDetails existingRecord = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == orderValue.OrderID); + + if (orderValue != null && existingRecord != null) + { + existingRecord.OrderID = orderValue.OrderID; + existingRecord.CustomerID = orderValue.CustomerID; + existingRecord.ShipCity = orderValue.ShipCity; + } + + } + else if (request.action == "insert") + { + // Insert record + if (request.value != null) + { + OrdersDetails.GetAllRecords().Insert(0, request.value); + } + } + else if (request.action == "remove") + { + // Delete record + OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == int.Parse(request.key.ToString()))); + } + + } + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel batchmodel) + { + if (batchmodel.added != null) + { + foreach (var addedOrder in batchmodel.added) + { + OrdersDetails.GetAllRecords().Insert(0, addedOrder); + } + } + if (batchmodel.changed != null) + { + foreach (var changedOrder in batchmodel.changed) + { + var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == changedOrder.OrderID); + if (existingOrder != null) + { + existingOrder.CustomerID = changedOrder.CustomerID; + existingOrder.ShipCity = changedOrder.ShipCity; + existingOrder.ShipCountry = changedOrder.ShipCountry; + // Update other properties as needed + } + } + } + if (batchmodel.deleted != null) + { + foreach (var deletedOrder in batchmodel.deleted) + { + var orderToDelete = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == deletedOrder.OrderID); + if (orderToDelete != null) + { + OrdersDetails.GetAllRecords().Remove(orderToDelete); + } + } + } + return Json(batchmodel); + } + + + 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; } + } + } +} \ No newline at end of file diff --git a/UrlAdaptor/UrlAdaptor/Controllers/WeatherForecastController.cs b/UrlAdaptor/UrlAdaptor/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..810000d --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace UrlAdaptor.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/UrlAdaptor/UrlAdaptor/Models/OrdersDetails.cs b/UrlAdaptor/UrlAdaptor/Models/OrdersDetails.cs new file mode 100644 index 0000000..4890c47 --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/Models/OrdersDetails.cs @@ -0,0 +1,58 @@ +namespace UrlAdaptor.Models +{ + public class OrdersDetails + { + public static List order = new List(); + public OrdersDetails() + { + + } + public OrdersDetails( + int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, + DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, + DateTime ShippedDate, string ShipAddress) + { + this.OrderID = OrderID; + this.CustomerID = CustomerId; + this.EmployeeID = EmployeeId; + this.Freight = Freight; + this.ShipCity = ShipCity; + this.Verified = Verified; + this.OrderDate = OrderDate; + this.ShipName = ShipName; + this.ShipCountry = ShipCountry; + this.ShippedDate = ShippedDate; + this.ShipAddress = ShipAddress; + } + + public static List GetAllRecords() + { + if (order.Count() == 0) + { + int code = 10000; + for (int i = 1; i < 10; i++) + { + order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6")); + order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123")); + order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo")); + order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7")); + order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S.")); + code += 5; + } + } + return order; + } + + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public double? Freight { get; set; } + public string? ShipCity { get; set; } + public bool? Verified { get; set; } + public DateTime OrderDate { get; set; } + public string? ShipName { get; set; } + public string? ShipCountry { get; set; } + public DateTime ShippedDate { get; set; } + public string? ShipAddress { get; set; } + } +} diff --git a/UrlAdaptor/UrlAdaptor/Program.cs b/UrlAdaptor/UrlAdaptor/Program.cs new file mode 100644 index 0000000..e3c9dd0 --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/Program.cs @@ -0,0 +1,28 @@ +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/UrlAdaptor/UrlAdaptor/Properties/launchSettings.json b/UrlAdaptor/UrlAdaptor/Properties/launchSettings.json new file mode 100644 index 0000000..4f9858a --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:29432", + "sslPort": 44390 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5286", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + // "launchUrl": "swagger", + "applicationUrl": "https://localhost:7073;http://localhost:5286", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj b/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj new file mode 100644 index 0000000..c11ecdf --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj.user b/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/UrlAdaptor.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/UrlAdaptor/UrlAdaptor/UrlAdaptor.http b/UrlAdaptor/UrlAdaptor/UrlAdaptor.http new file mode 100644 index 0000000..a793f7b --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/UrlAdaptor.http @@ -0,0 +1,6 @@ +@UrlAdaptor_HostAddress = http://localhost:5286 + +GET {{UrlAdaptor_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/UrlAdaptor/UrlAdaptor/WeatherForecast.cs b/UrlAdaptor/UrlAdaptor/WeatherForecast.cs new file mode 100644 index 0000000..648caed --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace UrlAdaptor +{ + 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/UrlAdaptor/UrlAdaptor/appsettings.Development.json b/UrlAdaptor/UrlAdaptor/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/UrlAdaptor/UrlAdaptor/appsettings.json b/UrlAdaptor/UrlAdaptor/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/UrlAdaptor/UrlAdaptor/wwwroot/css/index.css b/UrlAdaptor/UrlAdaptor/wwwroot/css/index.css new file mode 100644 index 0000000..46800d1 --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/wwwroot/css/index.css @@ -0,0 +1,2 @@ +body { +} diff --git a/UrlAdaptor/UrlAdaptor/wwwroot/index.html b/UrlAdaptor/UrlAdaptor/wwwroot/index.html new file mode 100644 index 0000000..af4cffe --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/wwwroot/index.html @@ -0,0 +1,33 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/UrlAdaptor/UrlAdaptor/wwwroot/js/index.js b/UrlAdaptor/UrlAdaptor/wwwroot/js/index.js new file mode 100644 index 0000000..a17897b --- /dev/null +++ b/UrlAdaptor/UrlAdaptor/wwwroot/js/index.js @@ -0,0 +1,26 @@ +ej.grids.Grid.Inject(ej.grids.Toolbar, ej.grids.Edit, ej.grids.Filter, ej.grids.Page, ej.grids.Sort); + +var data = new ej.data.DataManager({ + url: 'https://localhost:7073/api/Grid', + insertUrl: 'https://localhost:7073/api/Grid/Insert', + updateUrl: 'https://localhost:7073/api/Grid/Update', + removeUrl: 'https://localhost:7073/api/Grid/Remove', + adaptor: new ej.data.UrlAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowPaging: true, + allowSorting: true, + allowFiltering: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, isPrimaryKey: true, type: 'number' }, + { field: 'CustomerID', width: 140, headerText: 'Customer ID', type: 'string' }, + { field: 'ShipCity', headerText: 'ShipCity', width: 140 }, + { field: 'ShipCountry', headerText: 'ShipCountry', width: 140 } + ] +}); + +grid.appendTo('#Grid'); \ No newline at end of file diff --git a/WebMethodAdaptor/WebMethodAdaptor.sln b/WebMethodAdaptor/WebMethodAdaptor.sln new file mode 100644 index 0000000..27bc5df --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebMethodAdaptor", "WebMethodAdaptor\WebMethodAdaptor.csproj", "{360C4474-3D1D-403C-9978-53F638BD7FAB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {360C4474-3D1D-403C-9978-53F638BD7FAB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3164F0E4-6B1E-4342-8E30-A08AA69AE150} + EndGlobalSection +EndGlobal diff --git a/WebMethodAdaptor/WebMethodAdaptor/Controllers/GridController.cs b/WebMethodAdaptor/WebMethodAdaptor/Controllers/GridController.cs new file mode 100644 index 0000000..23427e2 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/Controllers/GridController.cs @@ -0,0 +1,205 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Syncfusion.EJ2.Base; +using WebMethodAdaptor.Models; + +namespace WebMethodAdaptor.Controllers +{ + public class GridController : Controller + { + // method to retrieve data + [HttpGet] + [Route("api/[controller]")] + public List GetOrderData() + { + // Retrieve all records and convert to list + var data = OrdersDetails.GetAllRecords().ToList(); + return data; + } + + // POST method to handle incoming data manager requests + [HttpPost] + [Route("api/[controller]")] + public object Post([FromBody] DataManager DataManagerRequest) + { + // Retrieve data source and convert to queryable + IQueryable DataSource = GetOrderData().AsQueryable(); + + // Initialize QueryableOperation + QueryableOperation queryableOperation = new QueryableOperation(); + + // Retrieve data manager value + DataManagerRequest dataManagerParams = DataManagerRequest.Value; + + + // Perform filtering operation if filtering is provided + if (dataManagerParams.Where != null && dataManagerParams.Where.Count > 0) + { + DataSource = queryableOperation.PerformFiltering(DataSource, dataManagerParams.Where, dataManagerParams.Where[0].Operator); + } + + // Perform search operation if search is provided + if (dataManagerParams.Search != null && dataManagerParams.Search.Count > 0) + { + DataSource = queryableOperation.PerformSearching(DataSource, dataManagerParams.Search); + } + + // Perform sorting operation if sorting is provided + if (dataManagerParams.Sorted != null && dataManagerParams.Sorted.Count > 0) + { + DataSource = queryableOperation.PerformSorting(DataSource, dataManagerParams.Sorted); + } + + // Get total record count after applying filters + int totalRecordsCount = DataSource.Count(); + + // Perform skip operation if skip value is provided + if (dataManagerParams.Skip != 0) + { + DataSource = queryableOperation.PerformSkip(DataSource, dataManagerParams.Skip); + } + + // Perform take operation if take value is provided + if (dataManagerParams.Take != 0) + { + DataSource = queryableOperation.PerformTake(DataSource, dataManagerParams.Take); + } + + // Return result and total record count + return new { result = DataSource, count = totalRecordsCount }; + } + + // POST method to handle record insertion + [HttpPost] + [Route("api/[controller]/Insert")] + public void Insert([FromBody] CRUDModel newRecord) + { + // Check if new record is not null + if (newRecord.value != null) + { + // Insert new record + OrdersDetails.GetAllRecords().Insert(0, newRecord.value); + } + } + + // POST method to handle record updates + [HttpPost] + [Route("api/[controller]/Update")] + public void Update([FromBody] CRUDModel updatedRecord) + { + // Retrieve updated order + var updatedOrder = updatedRecord.value; + if (updatedOrder != null) + { + // Find existing record + var data = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == updatedOrder.OrderID); + if (data != null) + { + // Update existing record + data.OrderID = updatedOrder.OrderID; + data.CustomerID = updatedOrder.CustomerID; + data.ShipCity = updatedOrder.ShipCity; + data.ShipCountry = updatedOrder.ShipCountry; + // Update other properties similarly + } + } + } + + // POST method to handle record removal + [HttpPost] + [Route("api/[controller]/Remove")] + public void Remove([FromBody] CRUDModel deletedRecord) + { + // Retrieve order ID from deleted record + int orderId = int.Parse(deletedRecord.key.ToString()); + // Find record to delete + var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId); + if (data != null) + { + // Remove record from data collection + OrdersDetails.GetAllRecords().Remove(data); + } + } + + [HttpPost] + [Route("api/[controller]/CrudUpdate")] + public void CrudUpdate([FromBody] CRUDModel request) + { + // perform update operation + if (request.action == "update") + { + var orderValue = request.value; + OrdersDetails existingRecord = OrdersDetails.GetAllRecords().Where(or => or.OrderID == orderValue.OrderID).FirstOrDefault(); + existingRecord.OrderID = orderValue.OrderID; + existingRecord.CustomerID = orderValue.CustomerID; + existingRecord.ShipCity = orderValue.ShipCity; + } + // perform insert operation + else if (request.action == "insert") + { + OrdersDetails.GetAllRecords().Insert(0, request.value); + } + // perform remove operation + else if (request.action == "remove") + { + OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(request.key.ToString())).FirstOrDefault()); + } + } + [HttpPost] + [Route("api/[controller]/BatchUpdate")] + public IActionResult BatchUpdate([FromBody] CRUDModel batchOperation) + { + if (batchOperation.added != null) + { + foreach (var addedOrder in batchOperation.added) + { + OrdersDetails.GetAllRecords().Insert(0, addedOrder); + } + } + if (batchOperation.changed != null) + { + foreach (var changedOrder in batchOperation.changed) + { + var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == changedOrder.OrderID); + if (existingOrder != null) + { + existingOrder.CustomerID = changedOrder.CustomerID; + existingOrder.ShipCity = changedOrder.ShipCity; + // Update other properties as needed + } + } + } + if (batchOperation.deleted != null) + { + foreach (var deletedOrder in batchOperation.deleted) + { + var orderToDelete = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == deletedOrder.OrderID); + if (orderToDelete != null) + { + OrdersDetails.GetAllRecords().Remove(orderToDelete); + } + } + } + return Json(batchOperation); + } + // Model for handling data manager requests + public class DataManager + { + public required DataManagerRequest Value { get; set; } + } + + // Model for handling CRUD operations + 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; } + } + + } +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/Controllers/WeatherForecastController.cs b/WebMethodAdaptor/WebMethodAdaptor/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..3089f8a --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebMethodAdaptor.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/WebMethodAdaptor/WebMethodAdaptor/Models/OrdersDetails.cs b/WebMethodAdaptor/WebMethodAdaptor/Models/OrdersDetails.cs new file mode 100644 index 0000000..baf6c7c --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/Models/OrdersDetails.cs @@ -0,0 +1,58 @@ +namespace WebMethodAdaptor.Models +{ + public class OrdersDetails + { + public static List order = new List(); + public OrdersDetails() + { + + } + public OrdersDetails( + int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, + DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, + DateTime ShippedDate, string ShipAddress) + { + this.OrderID = OrderID; + this.CustomerID = CustomerId; + this.EmployeeID = EmployeeId; + this.Freight = Freight; + this.ShipCity = ShipCity; + this.Verified = Verified; + this.OrderDate = OrderDate; + this.ShipName = ShipName; + this.ShipCountry = ShipCountry; + this.ShippedDate = ShippedDate; + this.ShipAddress = ShipAddress; + } + + public static List GetAllRecords() + { + if (order.Count() == 0) + { + int code = 10000; + for (int i = 1; i < 10; i++) + { + order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6")); + order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123")); + order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo")); + order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7")); + order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S.")); + code += 5; + } + } + return order; + } + + public int? OrderID { get; set; } + public string? CustomerID { get; set; } + public int? EmployeeID { get; set; } + public double? Freight { get; set; } + public string? ShipCity { get; set; } + public bool? Verified { get; set; } + public DateTime OrderDate { get; set; } + public string? ShipName { get; set; } + public string? ShipCountry { get; set; } + public DateTime ShippedDate { get; set; } + public string? ShipAddress { get; set; } + } +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/Program.cs b/WebMethodAdaptor/WebMethodAdaptor/Program.cs new file mode 100644 index 0000000..e3c9dd0 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/Program.cs @@ -0,0 +1,28 @@ +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/WebMethodAdaptor/WebMethodAdaptor/Properties/launchSettings.json b/WebMethodAdaptor/WebMethodAdaptor/Properties/launchSettings.json new file mode 100644 index 0000000..4f9858a --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:29432", + "sslPort": 44390 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5286", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + // "launchUrl": "swagger", + "applicationUrl": "https://localhost:7073;http://localhost:5286", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/WeatherForecast.cs b/WebMethodAdaptor/WebMethodAdaptor/WeatherForecast.cs new file mode 100644 index 0000000..10b8956 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace WebMethodAdaptor +{ + 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/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj new file mode 100644 index 0000000..c11ecdf --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj.user b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.http b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.http new file mode 100644 index 0000000..7fa2368 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/WebMethodAdaptor.http @@ -0,0 +1,6 @@ +@WebMethodAdaptor_HostAddress = http://localhost:5286 + +GET {{WebMethodAdaptor_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WebMethodAdaptor/WebMethodAdaptor/appsettings.Development.json b/WebMethodAdaptor/WebMethodAdaptor/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/appsettings.json b/WebMethodAdaptor/WebMethodAdaptor/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/wwwroot/css/index.css b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/css/index.css new file mode 100644 index 0000000..46800d1 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/css/index.css @@ -0,0 +1,2 @@ +body { +} diff --git a/WebMethodAdaptor/WebMethodAdaptor/wwwroot/index.html b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/index.html new file mode 100644 index 0000000..09458b3 --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/index.html @@ -0,0 +1,33 @@ + + + + EJ2 Grid + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/WebMethodAdaptor/WebMethodAdaptor/wwwroot/js/index.js b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/js/index.js new file mode 100644 index 0000000..30798af --- /dev/null +++ b/WebMethodAdaptor/WebMethodAdaptor/wwwroot/js/index.js @@ -0,0 +1,26 @@ +ej.grids.Grid.Inject(ej.grids.Toolbar, ej.grids.Edit, ej.grids.Filter, ej.grids.Page, ej.grids.Sort); + +var data = new ej.data.DataManager({ + url: 'https://localhost:7073/api/Grid', + insertUrl: 'https://localhost:7073/api/Grid/Insert', + updateUrl: 'https://localhost:7073/api/Grid/Update', + removeUrl: 'https://localhost:7073/api/Grid/Remove', + adaptor: new ej.data.WebMethodAdaptor() +}); + +var grid = new ej.grids.Grid({ + dataSource: data, + allowPaging: true, + allowSorting: true, + allowFiltering: true, + toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'], + editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' }, + columns: [ + { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, isPrimaryKey: true, type: 'number' }, + { field: 'CustomerID', width: 140, headerText: 'Customer ID', type: 'string' }, + { field: 'ShipCity', headerText: 'ShipCity', width: 140 }, + { field: 'ShipCountry', headerText: 'ShipCountry', width: 140 } + ] +}); + +grid.appendTo('#Grid'); \ No newline at end of file