-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6500043
commit 05b7c1b
Showing
6 changed files
with
194 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@using Goodtocode.Common.Extensions; | ||
|
||
@if (Result != null) | ||
{ | ||
<div class="row"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessSearch.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
@page "/business/search" | ||
@using Goodtocode.Common.Extensions; | ||
@using Goodtocode.Subjects.BlazorServer.Data; | ||
@using Goodtocode.Subjects.BlazorServer.Models; | ||
@using Goodtocode.Subjects.Domain; | ||
@using System.ComponentModel.DataAnnotations; | ||
@using Goodtocode.Subjects.Rcl; | ||
@using Microsoft.AspNetCore.Http.Extensions; | ||
|
||
@inject BusinessService Service | ||
@inject PageHistoryState PageHistory | ||
@inject NavigationManager UriHelper | ||
|
||
<PageTitle>Business Search</PageTitle> | ||
|
||
<EditForm Model="@SearchTerm" OnValidSubmit="@GetBusinessesAsync"> | ||
<DataAnnotationsValidator /> | ||
<div class="input-group mb-3"> | ||
<input type="text" class="form-control form-control-lg" placeholder="Search" aria-label="Search" aria-describedby="button-addon2" | ||
@bind="@SearchTerm"> | ||
<button class="btn btn-primary btn-lg" type="submit" id="button-addon2"><i class="bi bi-search"></i></button> | ||
</div> | ||
<ValidationSummary /> | ||
<div hidden="@string.IsNullOrEmpty(alertMessage)" class="alert alert-danger" role="alert">@alertMessage</div> | ||
<div hidden="@(!processing)" class="spinner-border text-primary center-screen" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</div> | ||
</EditForm> | ||
|
||
|
||
@if (businesses.Results.Count() > 0) | ||
{ | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Key</th> | ||
<th>Name</th> | ||
<th>Tax Number</th> | ||
<th style="width:5%;"></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var business in businesses.Results) | ||
{ | ||
<tr> | ||
<td>@business.BusinessKey</td> | ||
<td>@business.BusinessName</td> | ||
<td>@business.TaxNumber</td> | ||
<td class="nowrap" style="width:5%;"> | ||
<NavLink href="@($"/person/viewperson/{business.BusinessKey}")" class="btn btn-link oi oi-eye p-0 nounderline"></NavLink> | ||
<NavLink href="@($"/person/updateperson/{business.BusinessKey}")" class="btn btn-link oi oi-pencil p-0 nounderline"></NavLink> | ||
<button @onclick="@(() => DeleteBusinessAsync(business))" disabled="@business.IsDeleting" class="btn btn-link oi oi-trash p-0 nounderline"> | ||
@if (business.IsDeleting) { <span class="spinner-border spinner-border-sm"></span> } | ||
else { <span></span> } | ||
</button> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
@code { | ||
[Parameter] | ||
public int Page { get; set; } = 1; | ||
[Parameter] | ||
public string SearchTerm { get; set; } = string.Empty; | ||
private string alertMessage = string.Empty; | ||
private SearchModel businessSearch = new SearchModel(); | ||
private PagedResult<BusinessModel> businesses = new PagedResult<BusinessModel>(); | ||
private CancellationTokenSource cts = new CancellationTokenSource(); | ||
private bool processing; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
PageHistory.AddPageToHistory(UriHelper.Uri); | ||
base.OnInitialized(); | ||
} | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
await GetBusinessesAsync(); | ||
PageHistory.AddPageToHistory(UriHelper.Uri); | ||
} | ||
|
||
protected async Task SearchBoxKeyPress(KeyboardEventArgs ev) | ||
{ | ||
if (ev.Key == "Enter") | ||
{ | ||
await GetBusinessesAsync(); | ||
} | ||
} | ||
|
||
private async Task GetBusinessesAsync() | ||
{ | ||
alertMessage = string.Empty; | ||
|
||
businessSearch.Name = SearchTerm; | ||
|
||
if (!Validator.TryValidateObject(businessSearch, | ||
new ValidationContext(businessSearch, serviceProvider: null, items: null), new List<ValidationResult>(), true)) return; | ||
|
||
if (cts != null) cts.Cancel(); | ||
cts = new CancellationTokenSource(); | ||
try | ||
{ | ||
processing = true; | ||
await Task.Delay(500, cts.Token); | ||
businesses = await Service.GetBusinessesAsync(businessSearch.Name, Page); | ||
if (businesses.Results.Count() == 0) | ||
alertMessage = "No businesses found"; | ||
} | ||
catch (TaskCanceledException) | ||
{ | ||
// Ignore exception if task was cancelled | ||
} | ||
finally | ||
{ | ||
processing = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
private async Task DeleteBusinessAsync(BusinessModel business) | ||
{ | ||
alertMessage = string.Empty; | ||
|
||
if (cts != null) cts.Cancel(); | ||
cts = new CancellationTokenSource(); | ||
try | ||
{ | ||
processing = true; | ||
var businessToDelete = business; | ||
await Task.Delay(500, cts.Token); | ||
await Service.DeleteBusinessAsync(business.BusinessKey); | ||
await GetBusinessesAsync(); | ||
} | ||
catch (TaskCanceledException) | ||
{ | ||
// Ignore exception if task was cancelled | ||
} | ||
finally | ||
{ | ||
processing = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters