Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mst.Bithy Akter committed Sep 30, 2023
2 parents ca6fa95 + 9e6e436 commit 21ac4de
Show file tree
Hide file tree
Showing 73 changed files with 3,922 additions and 441 deletions.
8 changes: 6 additions & 2 deletions BlazorPwaApp/Client/App.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Router AppAssembly="@typeof(App).Assembly">
@using Microsoft.AspNetCore.Authorization;
@attribute [Authorize]

<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<RouteView RouteData="@routeData" DefaultLayout="@typeof(CustomLayout)" />
@*<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(CustomLayout)" />*@
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
Expand Down
5 changes: 5 additions & 0 deletions BlazorPwaApp/Client/BlazorPwaApp.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazorise" Version="1.3.1" />
<PackageReference Include="Blazorise.Bootstrap" Version="1.3.1" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.21" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.21" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
101 changes: 101 additions & 0 deletions BlazorPwaApp/Client/Pages/ChangePassword.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@page "/changepassword"
@page "/changepassword/{id:int}"
@layout MainLayout
@inject IUserAccountService UserAccountService
@inject IJSRuntime JsRuntime
@inject NavigationManager NavigationManager
@using BlazorPwaApp.Shared.Dto
@using BlazorPwaApp.Shared.Entities

<PageTitle>Change Password</PageTitle>
<h3 class="text-center fw-bold">Change Password</h3>

<div class="row justify-content-center">
<div class="col-md-10">

@if (!string.IsNullOrEmpty(ErrorMessage))
{
<p class="text-danger">@ErrorMessage</p>
}

<div class="card">
<div class="card-header">
<Span>Change Password</Span>
</div>
<div class="card-body ps-5 pe-5">

<EditForm Model="changePassword" OnSubmit="HandleSubmit">
<DataAnnotationsValidator />

<div class="form-group row mt-3">
<label class="control-label col-md-12 required">User Name</label>
<div class="col">
<InputText class="form-control" @bind-Value="changePassword.Username" />
<ValidationMessage For="@(() => changePassword.Username)" />
</div>
</div>

<div class="form-group row mt-3">
<label class="control-label col-md-12 required">Old Password</label>
<div class="col">
<InputText type="password" class="form-control" @bind-Value="changePassword.Password"></InputText>
<ValidationMessage For="@(() => changePassword.Password)" />
</div>
</div>

<div class="form-group row mt-3">
<label class="control-label col-md-12 required">Password</label>
<div class="col">
<InputText type="password" class="form-control" @bind-Value="changePassword.NewPassword"></InputText>
<ValidationMessage For="@(() => changePassword.NewPassword)" />
</div>
</div>

<div class="form-group row mt-3">
<label class="control-label col-md-12 required">Confirm Password</label>
<div class="col">
<InputText type="password" class="form-control" @bind-Value="changePassword.ConfirmPassword"></InputText>
<ValidationMessage For="@(() => changePassword.ConfirmPassword)" />
</div>
</div>

<div class="form-group mb-4 mt-4" align="center">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-danger mx-2" @onclick="GoToUserAccountPage">Back</button>
</div>
</EditForm>

</div>
</div>
</div>
</div>

@code {
[Parameter]
public int? Id { get; set; }

string btnText = string.Empty;
string ErrorMessage = string.Empty;

private ChangedPasswordDto changePassword = new ChangedPasswordDto();

async Task HandleSubmit()
{
try
{
await UserAccountService.ChangePassword(changePassword);

await JsRuntime.InvokeVoidAsync("alert", "Password changed successfully!");
NavigationManager.NavigateTo("countries");
}
catch (ApiException ex)
{
ErrorMessage = ex.Message;
}
}

private void GoToUserAccountPage()
{
NavigationManager.NavigateTo("/login");
}
}
1 change: 1 addition & 0 deletions BlazorPwaApp/Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/counter"
@layout MainLayout

<PageTitle>Counter</PageTitle>

Expand Down
146 changes: 109 additions & 37 deletions BlazorPwaApp/Client/Pages/Country.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@page "/countries"
@attribute [Authorize]
@layout MainLayout
@using BlazorPwaApp.Client.Services.CountryService;
@using static System.Net.WebRequestMethods;
@using BlazorPwaApp.Shared.Entities;
@using Microsoft.AspNetCore.Authorization;
@inject ICountryService CountryService
@inject IJSRuntime js
@inject NavigationManager NavigationManager
Expand All @@ -9,45 +13,90 @@

<h3>Countries</h3>

<button class="btn btn-primary" @onclick="CreateNewCountry">Create New Country</button>
<div class="row">
<div class="col-md-8">
<button class="btn btn-primary" @onclick="CreateNewCountry">Create New Country</button>
</div>

<table class="table">
<thead>
<tr>
<th>Country name</th>
<th>Country code</th>
<th>ISO Code2</th>
<th></th>
</tr>
</thead>

<tbody>
@foreach (var country in CountryService.Countries)
<div class="input-group col">
<input type="text" class="form-control" placeholder="Search country by name"
@bind="SearchString" @bind:event="oninput" @onkeyup="FilterCountry" />
@if (SearchString.Length > 0)
{
<div class="input-group-append">
<button class="btn btn-danger" @onclick="ResetSearch" style="font-size: 12px; margin-top: 5px; margin-left: 5px;">
<i class="oi oi-reload"></i>
</button>
</div>
}
</div>
</div>

@if (list != null)
{
<table class="table">
<thead>
<tr>
<td>@country.CountryName</td>
<td>@country.CountryCode</td>
<td>@country.ISOCode2</td>
<td>
<button class="btn btn-primary" @onclick="(() => ShowCountry(country.Oid))"><i class="oi oi-pencil"></i></button>
@*<button type="button" class="btn btn-danger mx-2" @onclick="(() => DeleteCountry(country.Oid))"><i class="oi oi-delete"></i></button>*@
<button type="button" class="btn btn-danger mx-2" @onclick="(() => ConfirmDelete(country.Oid, country.CountryName))"><i class="oi oi-delete"></i></button>
</td>
<th>Country name</th>
<th>Country code</th>
<th>ISO Code2</th>
<th></th>
</tr>
}
</tbody>
</table>
</thead>

@code {
<tbody>
@foreach (var country in list)
{
<tr>
<td>@country.CountryName</td>
<td>@country.CountryCode</td>
<td>@country.ISOCode2</td>
<td>
<button class="btn btn-primary" @onclick="(() => ShowCountry(country.Oid))"><i class="oi oi-pencil"></i></button>
<button type="button" class="btn btn-danger mx-2" @onclick="(() => ConfirmDelete(country.Oid, country.CountryName))"><i class="oi oi-delete"></i></button>
</td>
</tr>
}
</tbody>
</table>
}

protected List<Country> list = new List<Country>();
@code {

[Parameter]
public string Id { get; set; }
protected List<BlazorPwaApp.Shared.Entities.Country> list = new List<BlazorPwaApp.Shared.Entities.Country>();
protected List<BlazorPwaApp.Shared.Entities.Country> searchCountryData = new();
protected string SearchString { get; set; } = string.Empty;

protected override async Task OnInitializedAsync()
{
await CountryService.GetCountries();
await LoadCountries();
}

private async Task LoadCountries()
{
var countries = await CountryService.GetCountries();
list = countries;
searchCountryData = countries;
}

protected void FilterCountry()
{
if (!string.IsNullOrEmpty(SearchString))
{
list = searchCountryData
.Where(x => x.CountryName.IndexOf(SearchString, StringComparison.OrdinalIgnoreCase) != -1)
.ToList();
}
else
{
list = searchCountryData;
}
}

public void ResetSearch()
{
SearchString = string.Empty;
list = searchCountryData;
}

void ShowCountry(int id)
Expand All @@ -60,18 +109,41 @@
NavigationManager.NavigateTo("/createcountry");
}

//async Task DeleteCountry(int countryId)
//{
// await CountryService.DeleteCountry(countryId);
// await CountryService.GetCountries();
//}
async Task ConfirmDelete(int id, string countryName)
{
if (await js.InvokeAsync<bool>("confirm", $"Do you want to delete {countryName}'s ({id}) Record?"))
{
await CountryService.DeleteCountry(id);
await CountryService.GetCountries();

// Find and remove the deleted country from the list
var deletedCountry = list.FirstOrDefault(c => c.Oid == id);
if (deletedCountry != null)
{
list.Remove(deletedCountry);
}
}
}
}

@*<button class="btn btn-primary" @onclick="CreateNewCountry"><i class="fas fa-user-plus"></i> Create New Country</button>*@
@*<button type="button" class="btn btn-danger mx-2" @onclick="(() => DeleteCountry(country.Oid))"><i class="oi oi-delete"></i></button>*@

@*async Task ConfirmDelete(int id, string countryName)
{
if (await js.InvokeAsync<bool>("confirm", $"Do you want to delete {countryName}'s ({id}) Record?"))
{
await CountryService.DeleteCountry(id);
await CountryService.GetCountries();
}
}
}
protected override async Task OnInitializedAsync()
{
await CountryService.GetCountries();
}*@

@* async Task DeleteCountry(int countryId)
{
await CountryService.DeleteCountry(countryId);
await CountryService.GetCountries();
}*@
Loading

0 comments on commit 21ac4de

Please sign in to comment.