Skip to content

Commit

Permalink
Blazor Web App created.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalirajk2022 committed Dec 28, 2023
1 parent 1b34c24 commit a0f96d0
Show file tree
Hide file tree
Showing 32 changed files with 954 additions and 0 deletions.
21 changes: 21 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/BlazorWebApp.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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="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>
58 changes: 58 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@page "/counter"
@rendermode InteractiveAuto

@using Syncfusion.Blazor.Data
@using BlazorWebApp.Shared.Models
@using BlazorWebApp.Shared.Services

@inject ClientServices clientlibrary

<SfGrid DataSource="@LibraryBooks" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" TValue="Book">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler" TValue="Book"></GridEvents>
<GridColumns>
<GridColumn Field="@nameof(Book.Id)" IsPrimaryKey="true" IsIdentity="true" Visible="false"></GridColumn>
<GridColumn Field="@nameof(Book.Name)" Width="150"></GridColumn>
<GridColumn Field="@nameof(Book.Author)" Width="150"></GridColumn>
<GridColumn Field="@nameof(Book.Quantity)" Width="90" TextAlign="TextAlign.Right"></GridColumn>
<GridColumn Field="@nameof(Book.Price)" Width="90" Format="C2" TextAlign="TextAlign.Right"></GridColumn>
<GridColumn Field="@nameof(Book.Available)" DisplayAsCheckBox="true" Width="70"></GridColumn>
</GridColumns>
</SfGrid>

@code
{
public List<Book> LibraryBooks { get; set; }
protected override async Task OnInitializedAsync ()
{
LibraryBooks = await clientlibrary.GetBooks();
}
public async void ActionBeginHandler ( ActionEventArgs<Book> Args )
{
//Will be triggered when CRUD action is initiated
if (Args.Action == "Add")
{
// Insert the changes into your database here.
await clientlibrary.InsertBook(Args.Data);
}
if (Args.Action == "Edit")
{
//Update the changes into your database here.
await clientlibrary.UpdateBook(Args.Data.Id, Args.Data);
}
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
{
//Remove the record from your database
await clientlibrary.RemoveBook(Args.Data.Id);
}
}
public async void ActionCompleteHandler ( ActionEventArgs<Book> Args )
{
//will be triggered when CRUD action is complete.
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
{
LibraryBooks = await clientlibrary.GetBooks(); //to fetch the updated data from db to Grid
}
}
}

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 Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using BlazorWebApp.Shared.Services;
using Syncfusion.Blazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddScoped(http => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<ClientServices>();
builder.Services.AddSyncfusionBlazor();
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NAaF5cWWJCf1FpR2dGfV5yd0VFalhXTnNbUiweQnxTdEZiW31ecH1VQmRcWEZ3Vw==");

await builder.Build().RunAsync();
11 changes: 11 additions & 0 deletions BlazorWebApp/BlazorWebApp.Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@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
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="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</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
{

}
}
19 changes: 19 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Models/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace BlazorWebApp.Shared.Models;

public partial class Book
{
public long Id { get; set; }

public string Name { get; set; } = null!;

public string Author { get; set; } = null!;

public int? Quantity { get; set; }

public int Price { get; set; }

public bool? Available { get; set; }
}
44 changes: 44 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Models/LibraryContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace BlazorWebApp.Shared.Models;

public partial class LibraryContext : DbContext
{
public LibraryContext()
{
}

public LibraryContext(DbContextOptions<LibraryContext> options)
: base(options)
{
}

public virtual DbSet<Book> Books { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=Library;Integrated Security=True");

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Book>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__Book__3214EC07676591B9");

entity.ToTable("Book");

entity.Property(e => e.Author)
.HasMaxLength(100)
.IsUnicode(false);
entity.Property(e => e.Name)
.HasMaxLength(200)
.IsUnicode(false);
});

OnModelCreatingPartial(modelBuilder);
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
49 changes: 49 additions & 0 deletions BlazorWebApp/BlazorWebApp.Shared/Services/ClientServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using BlazorWebApp.Shared.Models;
using System;
using System.Collections.Generic;
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<Book>> GetBooks ()
{
var result = await _httpClient.GetFromJsonAsync<List<Book>>("https://localhost:7105/api/DataGrid");

return result;
}


public async Task<Book> InsertBook ( Book value )
{
await _httpClient.PostAsJsonAsync<Book>($"https://localhost:7105/api/DataGrid/", value);
return value;
}
public async Task<bool> RemoveBook ( long bookId )
{
HttpResponseMessage response = await _httpClient.DeleteAsync($"https://localhost:7105/api/DataGrid/{bookId}");

return true;
}

public async Task<Book> UpdateBook ( long bookId, Book updatedBook )
{
HttpResponseMessage response = await _httpClient.PutAsJsonAsync($"https://localhost:7105/api/DataGrid/{bookId}", updatedBook);

return updatedBook;

}
}
}
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", "{66327D5B-9BB5-4D94-BF32-752F5C4837DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebApp.Client", "BlazorWebApp.Client\BlazorWebApp.Client.csproj", "{1FA4080F-1572-434B-B8F9-E383F788DBFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorWebApp.Shared", "BlazorWebApp.Shared\BlazorWebApp.Shared.csproj", "{B6C5A60A-EE79-4E04-B357-CDCA8B98DAF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66327D5B-9BB5-4D94-BF32-752F5C4837DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66327D5B-9BB5-4D94-BF32-752F5C4837DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66327D5B-9BB5-4D94-BF32-752F5C4837DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66327D5B-9BB5-4D94-BF32-752F5C4837DD}.Release|Any CPU.Build.0 = Release|Any CPU
{1FA4080F-1572-434B-B8F9-E383F788DBFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FA4080F-1572-434B-B8F9-E383F788DBFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FA4080F-1572-434B-B8F9-E383F788DBFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FA4080F-1572-434B-B8F9-E383F788DBFC}.Release|Any CPU.Build.0 = Release|Any CPU
{B6C5A60A-EE79-4E04-B357-CDCA8B98DAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6C5A60A-EE79-4E04-B357-CDCA8B98DAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6C5A60A-EE79-4E04-B357-CDCA8B98DAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6C5A60A-EE79-4E04-B357-CDCA8B98DAF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BF77F438-3F6C-4D0D-9692-F9EB34FBAA64}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions BlazorWebApp/BlazorWebApp/BlazorWebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<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="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions BlazorWebApp/BlazorWebApp/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!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/material.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 a0f96d0

Please sign in to comment.