Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CQRS sample frontend #162

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />


<link rel="icon" type="image/png" href="favicon.ico" />
<HeadOutlet @rendermode="@InteractiveServer" />
</head>

<body>
<Routes @rendermode="@InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@inherits LayoutComponentBase

<MudThemingProvider />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />

<MudLayout>
<MudAppBar Elevation="1">
<MudText Typo="Typo.h5" Class="ml-3">Akka.NET SqlServer CQRS Demo</MudText>
</MudAppBar>
<MudMainContent Class="mt-16 pa-4">
@Body
</MudMainContent>
</MudLayout>

@code {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }

private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@page "/"
@using CqrsSqlServer.DataModel.Entities
@using CqrsSqlServer.DataModel
@using Microsoft.EntityFrameworkCore
@inject CqrsSqlServerContext DbContext

<PageTitle>Product Data</PageTitle>
<div class="d-flex flex-grow-1 gap-4">
<MudText Typo="Typo.h3" GutterBottom="true">Product Data</MudText>
<MudFab Color="Color.Primary" StartIcon="@Icons.Material.Filled.Refresh" OnClick="RefreshCallback"></MudFab>
</div>

<MudTable Items="_products" Hover="true" SortLabel="Sort By" Elevation="0" Loading="@_loading">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<ProductListing, object>(x=>x.ProductId)">Id</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.ProductName)">Name</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.Price)">Price</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.AllInventory)">Inventory</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.SoldUnits)">Sold</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.TotalRevenue)">Revenue</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.Created)">Created</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.LastModified)">Updated</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.ProductId</MudTd>
<MudTd DataLabel="Name">@context.ProductName</MudTd>
<MudTd DataLabel="Price">@context.Price</MudTd>
<MudTd DataLabel="Inventory">@context.AllInventory</MudTd>
<MudTd DataLabel="Sold">@context.SoldUnits</MudTd>
<MudTd DataLabel="Revenue">@context.TotalRevenue</MudTd>
<MudTd DataLabel="Created">@context.Created</MudTd>
<MudTd DataLabel="Updated">@context.LastModified</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{10, 50, 100}" />
</PagerContent>
</MudTable>

@code {
private ProductListing[] _products = Array.Empty<ProductListing>();
private bool _loading = true;

protected override async Task OnInitializedAsync()
{
_products = await DbContext.Products.ToArrayAsync();
_loading = false;
}

private async Task RefreshCallback()
{
_loading = true;
StateHasChanged();
_products = await DbContext.Products.ToArrayAsync();
_loading = false;
StateHasChanged();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>
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 CqrsSqlServer.Frontend
@using CqrsSqlServer.Frontend.Components
@using MudBlazor
@using MudBlazor.Services
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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


<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.*" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\CqrsSqlServer.DataModel\CqrsSqlServer.DataModel.csproj" />
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions src/cqrs/cqrs-sqlserver/CqrsSqlServer.Frontend/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using CqrsSqlServer.DataModel;
using CqrsSqlServer.Frontend.Components;
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;

namespace CqrsSqlServer.Frontend;

public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

builder.Services.AddMudServices();

var connectionString = builder.Configuration.GetConnectionString("AkkaSqlConnection");
if (connectionString is null)
throw new Exception("AkkaSqlConnection setting is missing");

builder.Services.AddDbContext<CqrsSqlServerContext>(options =>
{
// disable change tracking for all implementations of this context
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
options.UseSqlServer(connectionString);
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
12 changes: 12 additions & 0 deletions src/cqrs/cqrs-sqlserver/CqrsSqlServer.Frontend/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"AkkaSqlConnection": "Server=localhost,1533; Database=Akka; User Id=sa; Password=yourStrong(!)Password; TrustServerCertificate=true;"
}
}
20 changes: 20 additions & 0 deletions src/cqrs/cqrs-sqlserver/CqrsSqlServer.Frontend/wwwroot/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
This CSS file matches the color scheme from MudBlazor to Bootstrap when utilized for authentication.
The file remains available at all times for demonstration purposes,
but it is exclusively employed in the 'App.razor' component when authentication is enabled.
*/

.btn-primary {
text-transform: uppercase;
--bs-btn-bg: var(--mud-palette-primary) !important;
--bs-btn-hover-bg: var(--mud-palette-primary-darken) !important;
}

.nav-pills {
--bs-nav-pills-link-active-bg: var(--mud-palette-primary) !important;
}

.nav {
--bs-nav-link-color: var(--mud-palette-primary) !important;
--bs-nav-link-hover-color: var(--mud-palette-primary-darken) !important;
}
Binary file not shown.
8 changes: 8 additions & 0 deletions src/cqrs/cqrs-sqlserver/CqrsSqlServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.Backend", "Cq
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.DataModel", "CqrsSqlServer.DataModel\CqrsSqlServer.DataModel.csproj", "{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.Frontend", "CqrsSqlServer.Frontend\CqrsSqlServer.Frontend.csproj", "{D291AA52-B8AA-4A8C-A5F2-9323259DAACF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +32,11 @@ Global
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Release|Any CPU.Build.0 = Release|Any CPU
{D291AA52-B8AA-4A8C-A5F2-9323259DAACF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D291AA52-B8AA-4A8C-A5F2-9323259DAACF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D291AA52-B8AA-4A8C-A5F2-9323259DAACF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D291AA52-B8AA-4A8C-A5F2-9323259DAACF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
Loading