Skip to content

Commit

Permalink
Shady nagy/blazor enhance (dotnet-architecture#429)
Browse files Browse the repository at this point in the history
* - Using cdnjs not nuget on bootstrap and signalr.
- Bootstrap modal used for add, edit details and delete.

* EditForm inside modal-content

* Top close button action added

* Removed unused using.

* DeleteCookies moved inside AuthService

* ApplicationCore removed from BlazorAdmin dependencies

* SecureHttpClient removed

* Logout from identity manager added

* last thing to do in logout from admin is LogoutIdentityManager.

* JSRuntime used in AuthService without pass to the functions

* Link fixed when logout from MVC
  • Loading branch information
ShadyNagy authored Jul 25, 2020
1 parent f582182 commit 4e88618
Show file tree
Hide file tree
Showing 26 changed files with 531 additions and 515 deletions.
1 change: 0 additions & 1 deletion src/BlazorAdmin/BlazorAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
</ItemGroup>

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

Expand Down
5 changes: 5 additions & 0 deletions src/BlazorAdmin/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
public class Constants
{
public const string API_URL = "https://localhost:5099/api/";

public static class Roles
{
public const string ADMINISTRATORS = "Administrators";
}
}
}
5 changes: 0 additions & 5 deletions src/BlazorAdmin/CustomAuthStateProvider.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Net.Http;
using System.Net.Http.Json;
using BlazorAdmin.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.eShopWeb;
using Microsoft.Extensions.Logging;
using Shared.Authorization;

Expand Down
37 changes: 0 additions & 37 deletions src/BlazorAdmin/Network/SecureHttpClient.cs

This file was deleted.

174 changes: 104 additions & 70 deletions src/BlazorAdmin/Pages/CatalogItemPage/Create.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,101 @@

@namespace BlazorAdmin.Pages.CatalogItemPage

<h2 class="esh-body-title">Create</h2>

<div>
<EditForm Model="_item" OnValidSubmit="@CreateClick">
<DataAnnotationsValidator />

<div class="form-group">
<label class="control-label col-md-2">Name</label>
<div class="col-md-3">
<InputText class="form-control" @bind-Value="_item.Name" />
<ValidationMessage For="(() => _item.Name)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Description</label>
<div class="col-md-3">
<InputText class="form-control" @bind-Value="_item.Description" />
<ValidationMessage For="(() => _item.Description)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Brand</label>
<div class="col-md-3">
<InputSelect @bind-Value="_item.CatalogBrandId" class="form-control">
@foreach (var brand in Brands)
<div class="modal @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay">
<div class="modal-dialog" role="document">
<div class="modal-content">
<EditForm Model="_item" OnValidSubmit="@CreateClick">
<DataAnnotationsValidator />
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
@if (_item == null)
{
<option value="@brand.Id">@brand.Name</option>
<Spinner></Spinner>
}
</InputSelect>
<ValidationMessage For="(() => _item.CatalogBrandId)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Type</label>
<div class="col-md-3">
<InputSelect @bind-Value="_item.CatalogTypeId" class="form-control">
@foreach (var type in Types)
else
{
<option value="@type.Id">@type.Name</option>
<div class="form-group">
<label class="control-label col-md-2">Name</label>
<div class="col-md-12">
<InputText class="form-control" @bind-Value="_item.Name" />
<ValidationMessage For="(() => _item.Name)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Description</label>
<div class="col-md-12">
<InputText class="form-control" @bind-Value="_item.Description" />
<ValidationMessage For="(() => _item.Description)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Brand</label>
<div class="col-md-12">
<InputSelect @bind-Value="_item.CatalogBrandId" class="form-control">
@foreach (var brand in Brands)
{
<option value="@brand.Id">@brand.Name</option>
}
</InputSelect>
<ValidationMessage For="(() => _item.CatalogBrandId)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Type</label>
<div class="col-md-12">
<InputSelect @bind-Value="_item.CatalogTypeId" class="form-control">
@foreach (var type in Types)
{
<option value="@type.Id">@type.Name</option>
}
</InputSelect>
<ValidationMessage For="(() => _item.CatalogTypeId)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Price</label>
<div class="col-md-12">
<InputNumber @bind-Value="_item.Price" class="form-control" />
<ValidationMessage For="(() => _item.Price)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Picture name</label>
<div class="col-md-12 esh-form-information">
Uploading images not allowed for this version.
</div>
</div>
}
</InputSelect>
<ValidationMessage For="(() => _item.CatalogTypeId)" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="Close">Cancel</button>
<button type="submit" class="btn btn-primary">
Create
</button>
</div>
</EditForm>
</div>
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Price</label>
<div class="col-md-3">
<InputNumber @bind-Value="_item.Price" class="form-control" />
<ValidationMessage For="(() => _item.Price)" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2">Picture name</label>
<div class="col-md-4 esh-form-information">
Uploading images not allowed for this version.
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-3 text-right esh-button-actions">
<a href="" @onclick="@(() => OnCloseClick.InvokeAsync(null))" @onclick:preventDefault class="btn btn-secondary">
Cancel
</a>
<button type="submit" class="btn esh-button btn-primary">
Create
</button>
</div>
</div>
</EditForm>
</div>
@if (_showCreateModal)
{
<div class="modal-backdrop fade show"></div>
}

@code {

Expand All @@ -91,21 +111,35 @@
[Parameter]
public EventCallback<string> OnCloseClick { get; set; }

private string _modalDisplay = "none;";
private string _modalClass = "";
private bool _showCreateModal = false;
private readonly CreateCatalogItemRequest _item = new CreateCatalogItemRequest();

protected override async Task OnAfterRenderAsync(bool firstRender)
private async Task CreateClick()
{
await new BlazorAdmin.Services.CatalogItemService.Create(Auth).HandleAsync(_item);
await OnCloseClick.InvokeAsync(null);
Close();
}

public void Open()
{
Logger.LogInformation("Now loading... /Catalog/Create");

_item.CatalogTypeId = Types.First().Id;
_item.CatalogBrandId = Brands.First().Id;

await base.OnAfterRenderAsync(firstRender);
_modalDisplay = "block;";
_modalClass = "Show";
_showCreateModal = true;
}

private async Task CreateClick()
public void Close()
{
await new BlazorAdmin.Services.CatalogItemService.Create(Auth).HandleAsync(_item);
await OnCloseClick.InvokeAsync(null);
_modalDisplay = "none";
_modalClass = "";
_showCreateModal = false;
OnCloseClick.InvokeAsync(null);
}
}
Loading

0 comments on commit 4e88618

Please sign in to comment.