Skip to content

Commit

Permalink
Merge pull request #2 from SyncfusionExamples/861193-Dapper
Browse files Browse the repository at this point in the history
Local sample updated for dapper data binding.
  • Loading branch information
rajendranr-5483 authored Jan 18, 2024
2 parents 5c4a172 + 18912e2 commit c0c027a
Show file tree
Hide file tree
Showing 32 changed files with 935 additions and 0 deletions.
22 changes: 22 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/BlazorWebApp.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Syncfusion.Blazor.Grid" Version="24.1.41" />
<PackageReference Include="Syncfusion.Blazor.Themes" Version="24.1.41" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorWebApp.Shared\BlazorWebApp.Shared.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@page "/counter"
@rendermode InteractiveServer
@using BlazorWebApp.Shared.Data

<SfGrid TValue="Bug" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<SfDataManager AdaptorInstance="typeof(BugDataAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field="@nameof(Bug.Id)" IsPrimaryKey="true" Visible="false"></GridColumn>
<GridColumn Field="@nameof(Bug.Summary)" Width="100"></GridColumn>
<GridColumn Field="@nameof(Bug.BugPriority)" HeaderText="Priority" Width="100"></GridColumn>
<GridColumn Field="@nameof(Bug.Assignee)" Width="100"></GridColumn>
<GridColumn Field="@nameof(Bug.BugStatus)" HeaderText="Status" Width="100"></GridColumn>
</GridColumns>
</SfGrid>
11 changes: 11 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using BlazorWebApp.Shared.Data;
using BlazorWebApp.Shared.Services;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Syncfusion.Blazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddSyncfusionBlazor();
builder.Services.AddScoped<BugDataAdaptor>();
builder.Services.AddScoped<ClientServices>();

await builder.Build().RunAsync();
12 changes: 12 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using BlazorWebApp.Client
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
8 changes: 8 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
17 changes: 17 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/BlazorWebApp.Shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Syncfusion.Blazor.Grid" Version="24.1.41" />
<PackageReference Include="Syncfusion.Blazor.Themes" Version="24.1.41" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BlazorWebApp.Shared
{
public class Class1
{

}
}
21 changes: 21 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Data/Bug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlazorWebApp.Shared.Data
{
public class Bug
{
public int Id { get; set; }

public string Summary { get; set; }

public string BugPriority { get; set; }

public string Assignee { get; set; }

public string BugStatus { get; set; }
}
}
39 changes: 39 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Data/BugDataAdaptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Syncfusion.Blazor.Data;
using Syncfusion.Blazor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using BlazorWebApp.Shared.Services;

namespace BlazorWebApp.Shared.Data
{
public class BugDataAdaptor : DataAdaptor
{

ClientServices BugDetails = new ClientServices(new HttpClient());
public override async Task<object> ReadAsync ( DataManagerRequest dataManagerRequest, string key = null )
{
List<Bug> bugs = await BugDetails.GetBugs();
int count = await BugDetails.GetBugCountAsync();
return dataManagerRequest.RequiresCounts ? new DataResult() { Result = bugs, Count = count } : count;
}
public override async Task<object> InsertAsync ( DataManager dataManager, object data, string key )
{
await BugDetails.InsertBug(data as Bug);
return data;
}
public override async Task<object> UpdateAsync ( DataManager dataManager, object data, string keyField, string key )
{
await BugDetails.UpdateBug(data as Bug);
return data;
}
public override async Task<object> RemoveAsync ( DataManager dataManager, object primaryKeyValue, string keyField, string key )
{
await BugDetails.RemoveBug(Convert.ToInt32(primaryKeyValue));
return primaryKeyValue;
}
}
}
70 changes: 70 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Services/ClientDataGridService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using BlazorWebApp.Shared.Data;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace BlazorWebApp.Shared.Services
{
public class ClientServices
{
private readonly HttpClient _httpClient;

public ClientServices ( HttpClient httpClient )
{
_httpClient = httpClient;

}

public async Task<List<Bug>> GetBugs ()
{
var result = await _httpClient.GetFromJsonAsync<List<Bug>>("https://localhost:7112/api/DataGrid");

return result;
}


public async Task<Bug> InsertBug ( Bug value )
{
await _httpClient.PostAsJsonAsync<Bug>($"https://localhost:7112/api/DataGrid/", value);
return value;
}
public async Task<int> RemoveBug ( int BugId )
{
HttpResponseMessage response = await _httpClient.DeleteAsync($"https://localhost:7112/api/DataGrid/{BugId}");

return BugId;
}

public async Task<Bug> UpdateBug ( Bug updatedBug )
{
HttpResponseMessage response = await _httpClient.PutAsJsonAsync($"https://localhost:7112/api/DataGrid/", updatedBug);

return updatedBug;

}
public async Task<int> GetBugCountAsync ()
{
var response = await _httpClient.GetAsync("https://localhost:7112/api/DataGrid/BugCount");

if (response.IsSuccessStatusCode)
{
// Assuming the API returns an integer value for bug count
int bugCount = await response.Content.ReadFromJsonAsync<int>();
return bugCount;
}
else
{
// Handle the error response
// You might want to return a default value or throw an exception
return 0;
}

}
}
}
37 changes: 37 additions & 0 deletions BlazorWebApp/BlazorWebApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebApp", "BlazorWebApp\BlazorWebApp.csproj", "{CB1CB133-7A9F-40BD-866C-397563215035}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebApp.Client", "BlazorWebApp.Client\BlazorWebApp.Client.csproj", "{74CC6D2A-2AE8-4BB0-9D98-B374B51E2C52}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebApp.Shared", "BlazorWebApp.Shared\BlazorWebApp.Shared.csproj", "{653BABC2-E6FB-4B39-A88C-693CB3FFB49E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CB1CB133-7A9F-40BD-866C-397563215035}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB1CB133-7A9F-40BD-866C-397563215035}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB1CB133-7A9F-40BD-866C-397563215035}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB1CB133-7A9F-40BD-866C-397563215035}.Release|Any CPU.Build.0 = Release|Any CPU
{74CC6D2A-2AE8-4BB0-9D98-B374B51E2C52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74CC6D2A-2AE8-4BB0-9D98-B374B51E2C52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74CC6D2A-2AE8-4BB0-9D98-B374B51E2C52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74CC6D2A-2AE8-4BB0-9D98-B374B51E2C52}.Release|Any CPU.Build.0 = Release|Any CPU
{653BABC2-E6FB-4B39-A88C-693CB3FFB49E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{653BABC2-E6FB-4B39-A88C-693CB3FFB49E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{653BABC2-E6FB-4B39-A88C-693CB3FFB49E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{653BABC2-E6FB-4B39-A88C-693CB3FFB49E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BEF34720-1062-4CB0-8186-585289E6EF39}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions BlazorWebApp/BlazorWebApp/BlazorWebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorWebApp.Client\BlazorWebApp.Client.csproj" />
<ProjectReference Include="..\BlazorWebApp.Shared\BlazorWebApp.Shared.csproj" />
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions BlazorWebApp/BlazorWebApp/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="BlazorWebApp.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link  href="_content/Syncfusion.Blazor.Themes/bootstrap4.css"  rel="stylesheet" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
</body>

</html>
23 changes: 23 additions & 0 deletions BlazorWebApp/BlazorWebApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Loading

0 comments on commit c0c027a

Please sign in to comment.