Skip to content

Commit

Permalink
wired delete
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtocode committed Jul 3, 2023
1 parent 931c1e6 commit 804b2b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ public static class IQueryableExtensions
{
public static async Task<PagedResult<T>> GetPagedAsync<T>(this IQueryable<T> query, int page, int pageSize, CancellationToken cancellationToken) where T : class
{
var result = new PagedResult<T>();
result.CurrentPage = page;
result.PageSize = pageSize;
result.RowCount = query.Count();
var result = new PagedResult<T>
{
CurrentPage = page,
PageSize = pageSize,
RowCount = query.Count()
};

var pageCount = (double)result.RowCount / pageSize;
result.PageCount = (int)Math.Ceiling(pageCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

@code {
[Parameter]
public BusinessModel business { get; set; }
public BusinessModel business { get; set; } = new BusinessModel();
[Parameter]
public string ButtonText { get; set; } = "Save";
[Parameter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<PageTitle>Business Search</PageTitle>

<EditForm Model="@SearchTerm" OnValidSubmit="@GetBusinesses">
<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"
Expand Down Expand Up @@ -47,9 +47,9 @@
<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 text-primary p-0 nounderline"></NavLink>
<NavLink href="@($"/person/updateperson/{business.BusinessKey}")" class="btn btn-link oi oi-pencil text-warning p-0 nounderline"></NavLink>
<button @onclick="@(() => DeleteBusiness(business.BusinessKey))" disabled="@business.IsDeleting" class="btn btn-link oi oi-trash text-danger p-0 nounderline">
<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>
Expand Down Expand Up @@ -79,19 +79,19 @@

protected override async Task OnParametersSetAsync()
{
await GetBusinesses();
await GetBusinessesAsync();
PageHistory.AddPageToHistory(UriHelper.Uri);
}

protected async Task SearchBoxKeyPress(KeyboardEventArgs ev)
{
if (ev.Key == "Enter")
{
await GetBusinesses();
await GetBusinessesAsync();
}
}

private async Task GetBusinesses()
private async Task GetBusinessesAsync()
{
alertMessage = string.Empty;

Expand All @@ -106,7 +106,7 @@
{
processing = true;
await Task.Delay(500, cts.Token);
businesses = await Service.GetBusinessesAsync(businessSearch.Name, 1);
businesses = await Service.GetBusinessesAsync(businessSearch.Name, Page);
if (businesses.Results.Count() == 0)
alertMessage = "No businesses found";
}
Expand All @@ -121,17 +121,28 @@
}
}

private async Task DeleteBusiness(Guid businessKey)
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();
}
}

//private async void DeletePerson(Person _person)
//{
// var person = _person;
// person.IsDeleting = true;
// await PersonService.DeletePerson(person.PersonId);
// people = await PersonService.GetPeople(null, Page);
// StateHasChanged();
//}
}

0 comments on commit 804b2b8

Please sign in to comment.