diff --git a/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/DashboardDataResponse.cs b/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/DashboardDataResponse.cs index d7a256d1c..666d04e94 100644 --- a/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/DashboardDataResponse.cs +++ b/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/DashboardDataResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData +namespace BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData { public class DashboardDataResponse { @@ -13,4 +7,4 @@ public class DashboardDataResponse public int UserCount { get; set; } public int RoleCount { get; set; } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/GetDashboardDataQuery.cs b/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/GetDashboardDataQuery.cs index 4427bd802..2cf95e2d9 100644 --- a/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/GetDashboardDataQuery.cs +++ b/BlazorHero.CleanArchitecture.Application/Features/Dashboard/GetData/GetDashboardDataQuery.cs @@ -4,10 +4,6 @@ using BlazorHero.CleanArchitecture.Shared.Wrapper; using MediatR; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -27,6 +23,7 @@ public GetDashboardDataQueryHandler(IUnitOfWork unitOfWork, IUserService userSer _userService = userService; _roleService = roleService; } + public async Task> Handle(GetDashboardDataQuery query, CancellationToken cancellationToken) { var response = new DashboardDataResponse(); @@ -38,4 +35,4 @@ public async Task> Handle(GetDashboardDataQuery qu } } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IBrandRepository.cs b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IBrandRepository.cs index b0bbb3318..a5be71b17 100644 --- a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IBrandRepository.cs +++ b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IBrandRepository.cs @@ -1,9 +1,4 @@ -using BlazorHero.CleanArchitecture.Domain.Entities.Catalog; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories +namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories { public interface IBrandRepository { diff --git a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IProductRepository.cs b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IProductRepository.cs index f0bc03def..d38eaa435 100644 --- a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IProductRepository.cs +++ b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IProductRepository.cs @@ -1,7 +1,4 @@ -using BlazorHero.CleanArchitecture.Domain.Entities.Catalog; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories { diff --git a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IUnitOfWork.cs b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IUnitOfWork.cs index 815929252..c4f6a065a 100644 --- a/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IUnitOfWork.cs +++ b/BlazorHero.CleanArchitecture.Application/Interfaces/Repositories/IUnitOfWork.cs @@ -1,6 +1,5 @@ using BlazorHero.CleanArchitecture.Domain.Contracts; using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -9,7 +8,9 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Repositories public interface IUnitOfWork : IDisposable { IRepositoryAsync Repository() where T : AuditableEntity; + Task Commit(CancellationToken cancellationToken); + Task Rollback(); } } \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IRoleService.cs b/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IRoleService.cs index 920609c92..bb3d970a6 100644 --- a/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IRoleService.cs +++ b/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IRoleService.cs @@ -10,6 +10,7 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity public interface IRoleService : IService { Task>> GetAllAsync(); + Task GetCountAsync(); Task> GetByIdAsync(string id); diff --git a/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IUserService.cs b/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IUserService.cs index 51802ddce..3ce6250e7 100644 --- a/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IUserService.cs +++ b/BlazorHero.CleanArchitecture.Application/Interfaces/Services/Identity/IUserService.cs @@ -10,6 +10,7 @@ namespace BlazorHero.CleanArchitecture.Application.Interfaces.Services.Identity public interface IUserService : IService { Task>> GetAllAsync(); + Task GetCountAsync(); Task> GetAsync(string userId); diff --git a/BlazorHero.CleanArchitecture.Client.Infrastructure/Authentication/BlazorHeroStateProvider.cs b/BlazorHero.CleanArchitecture.Client.Infrastructure/Authentication/BlazorHeroStateProvider.cs index c5366a83d..e515b610a 100644 --- a/BlazorHero.CleanArchitecture.Client.Infrastructure/Authentication/BlazorHeroStateProvider.cs +++ b/BlazorHero.CleanArchitecture.Client.Infrastructure/Authentication/BlazorHeroStateProvider.cs @@ -45,14 +45,17 @@ public void MarkUserAsLoggedOut() NotifyAuthenticationStateChanged(authState); } - public async Task GetAuthenticationStateProviderUserAsync() + + public async Task GetAuthenticationStateProviderUserAsync() { ClaimsPrincipal AuthenticationStateProviderUser = new ClaimsPrincipal(); var state = await this.GetAuthenticationStateAsync(); AuthenticationStateProviderUser = state.User; return AuthenticationStateProviderUser; } + public ClaimsPrincipal AuthenticationStateUser { get; set; } + public override async Task GetAuthenticationStateAsync() { var savedToken = await _localStorage.GetItemAsync("authToken"); diff --git a/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/DashboardManager.cs b/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/DashboardManager.cs index 6bf4abcbd..26886ab23 100644 --- a/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/DashboardManager.cs +++ b/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/DashboardManager.cs @@ -2,10 +2,7 @@ using BlazorHero.CleanArchitecture.Client.Infrastructure.Extensions; using BlazorHero.CleanArchitecture.Shared.Wrapper; using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Text; using System.Threading.Tasks; namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard @@ -29,10 +26,8 @@ public async Task> GetDataAsync() } catch (Exception ex) { - throw; } - } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/IDashboardManager.cs b/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/IDashboardManager.cs index 3c135f09f..2b2c1ca68 100644 --- a/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/IDashboardManager.cs +++ b/BlazorHero.CleanArchitecture.Client.Infrastructure/Managers/Dashboard/IDashboardManager.cs @@ -7,6 +7,5 @@ namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Managers.Dashboard public interface IDashboardManager : IManager { Task> GetDataAsync(); - } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/DashboardEndpoint.cs b/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/DashboardEndpoint.cs index 50990cd3e..872c8e797 100644 --- a/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/DashboardEndpoint.cs +++ b/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/DashboardEndpoint.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Routes +namespace BlazorHero.CleanArchitecture.Client.Infrastructure.Routes { public class DashboardEndpoint { public static string GetData = "api/v1/dashboard"; } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/ProductsEndpoint.cs b/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/ProductsEndpoint.cs index 5e4a9ce9d..28d794353 100644 --- a/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/ProductsEndpoint.cs +++ b/BlazorHero.CleanArchitecture.Client.Infrastructure/Routes/ProductsEndpoint.cs @@ -6,7 +6,9 @@ public static string GetAllPaged(int pageNumber, int pageSize) { return $"api/v1/products?pageNumber={pageNumber}&pageSize={pageSize}"; } + public static string GetCount = "api/v1/products/count"; + public static string GetProductImage(int productId) { return $"api/v1/products/image/{productId}"; diff --git a/BlazorHero.CleanArchitecture.Infrastructure/Migrations/20210317175826_initial.cs b/BlazorHero.CleanArchitecture.Infrastructure/Migrations/20210317175826_initial.cs index d231ea9d9..0135930a8 100644 --- a/BlazorHero.CleanArchitecture.Infrastructure/Migrations/20210317175826_initial.cs +++ b/BlazorHero.CleanArchitecture.Infrastructure/Migrations/20210317175826_initial.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; +using System; namespace BlazorHero.CleanArchitecture.Infrastructure.Migrations { @@ -314,4 +314,4 @@ protected override void Down(MigrationBuilder migrationBuilder) schema: "Identity"); } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture.Infrastructure/Repositories/BrandRepository.cs b/BlazorHero.CleanArchitecture.Infrastructure/Repositories/BrandRepository.cs index 569b7a7d5..b816b8429 100644 --- a/BlazorHero.CleanArchitecture.Infrastructure/Repositories/BrandRepository.cs +++ b/BlazorHero.CleanArchitecture.Infrastructure/Repositories/BrandRepository.cs @@ -1,9 +1,4 @@ using BlazorHero.CleanArchitecture.Application.Interfaces.Repositories; -using BlazorHero.CleanArchitecture.Domain.Entities.Catalog; -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace BlazorHero.CleanArchitecture.Infrastructure.Repositories { diff --git a/BlazorHero.CleanArchitecture.Infrastructure/Services/Identity/RoleService.cs b/BlazorHero.CleanArchitecture.Infrastructure/Services/Identity/RoleService.cs index 7dfed5cb9..6dad3e064 100644 --- a/BlazorHero.CleanArchitecture.Infrastructure/Services/Identity/RoleService.cs +++ b/BlazorHero.CleanArchitecture.Infrastructure/Services/Identity/RoleService.cs @@ -157,6 +157,7 @@ public async Task> UpdatePermissionsAsync(PermissionRequest reque return Result.Fail(ex.Message); } } + public async Task GetCountAsync() { var count = await _roleManager.Roles.CountAsync(); diff --git a/BlazorHero.CleanArchitecture/Client/Pages/Catalog/AddEditProductModal.razor.cs b/BlazorHero.CleanArchitecture/Client/Pages/Catalog/AddEditProductModal.razor.cs index c361591e8..eab6e5217 100644 --- a/BlazorHero.CleanArchitecture/Client/Pages/Catalog/AddEditProductModal.razor.cs +++ b/BlazorHero.CleanArchitecture/Client/Pages/Catalog/AddEditProductModal.razor.cs @@ -53,7 +53,6 @@ public void Cancel() private async Task SaveAsync() { - form.Validate(); if (form.IsValid) { diff --git a/BlazorHero.CleanArchitecture/Client/Pages/Catalog/Products.razor.cs b/BlazorHero.CleanArchitecture/Client/Pages/Catalog/Products.razor.cs index e51b86bce..caca3d831 100644 --- a/BlazorHero.CleanArchitecture/Client/Pages/Catalog/Products.razor.cs +++ b/BlazorHero.CleanArchitecture/Client/Pages/Catalog/Products.razor.cs @@ -1,7 +1,5 @@ using BlazorHero.CleanArchitecture.Application.Features.Products.Queries.GetAllPaged; using BlazorHero.CleanArchitecture.Application.Requests.Catalog; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Authorization; using MudBlazor; using System; using System.Collections.Generic; @@ -25,12 +23,14 @@ private async Task> ServerReload(TableSta await LoadData(state.Page, state.PageSize); return new TableData() { TotalItems = totalItems, Items = pagedData }; } + private ClaimsPrincipal AuthenticationStateProviderUser { get; set; } protected override async Task OnParametersSetAsync() { AuthenticationStateProviderUser = await _stateProvider.GetAuthenticationStateProviderUserAsync(); } + private async Task LoadData(int pageNumber, int pageSize) { var request = new GetAllPagedProductsRequest { PageSize = pageSize, PageNumber = pageNumber + 1 }; diff --git a/BlazorHero.CleanArchitecture/Client/Pages/Content/Dashboard.razor b/BlazorHero.CleanArchitecture/Client/Pages/Content/Dashboard.razor index 9cb50762e..ef0efb44f 100644 --- a/BlazorHero.CleanArchitecture/Client/Pages/Content/Dashboard.razor +++ b/BlazorHero.CleanArchitecture/Client/Pages/Content/Dashboard.razor @@ -4,7 +4,7 @@ - +
Products @ProductCount @@ -13,7 +13,7 @@ - +
Brands @BrandCount @@ -22,7 +22,7 @@ - +
Registered Users @UserCount @@ -31,7 +31,7 @@ - +
Registered Roles @RoleCount @@ -64,7 +64,7 @@ private async Task LoadDataAsync() { var data = await _dashboardManager.GetDataAsync(); - if(data.Succeeded) + if (data.Succeeded) { ProductCount = data.Data.ProductCount; BrandCount = data.Data.BrandCount; @@ -72,4 +72,4 @@ RoleCount = data.Data.RoleCount; } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture/Client/Pages/Content/Resources.razor b/BlazorHero.CleanArchitecture/Client/Pages/Content/Resources.razor deleted file mode 100644 index c98cb5180..000000000 --- a/BlazorHero.CleanArchitecture/Client/Pages/Content/Resources.razor +++ /dev/null @@ -1,43 +0,0 @@ -@page "/resources" -@inject Microsoft.Extensions.Localization.IStringLocalizer localizer - - - - - - - - - - - - - - @localizer["Awesome Blazor"] - @localizer["Awesome Blazor Description"] - - - - - - - - - - - - - - - - - @localizer["Awesome Blazor"] - @localizer["Awesome Blazor Description"] - - - - - - - - \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture/Client/Pages/Identity/Security.razor.cs b/BlazorHero.CleanArchitecture/Client/Pages/Identity/Security.razor.cs index b041ca25e..d23528552 100644 --- a/BlazorHero.CleanArchitecture/Client/Pages/Identity/Security.razor.cs +++ b/BlazorHero.CleanArchitecture/Client/Pages/Identity/Security.razor.cs @@ -19,7 +19,21 @@ protected override void OnInitialized() private async Task ChangePasswordAsync() { - await _accountManager.ChangePasswordAsync(passwordModel); + var response = await _accountManager.ChangePasswordAsync(passwordModel); + if(response.Succeeded) + { + _snackBar.Add("Password Changed!",Severity.Success); + passwordModel.Password = string.Empty; + passwordModel.NewPassword = string.Empty; + passwordModel.ConfirmNewPassword = string.Empty; + } + else + { + foreach(var error in response.Messages) + { + _snackBar.Add(error, Severity.Error); + } + } } private IEnumerable PasswordStrength(string pw) diff --git a/BlazorHero.CleanArchitecture/Client/Shared/NavMenu.razor b/BlazorHero.CleanArchitecture/Client/Shared/NavMenu.razor index 18e2ea33d..459abcc6c 100644 --- a/BlazorHero.CleanArchitecture/Client/Shared/NavMenu.razor +++ b/BlazorHero.CleanArchitecture/Client/Shared/NavMenu.razor @@ -39,7 +39,6 @@ } } - @localizer["Communication"] @localizer["Chat"] @@ -63,7 +62,6 @@ } } - @code { diff --git a/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/BrandsController.cs b/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/BrandsController.cs index 1f35d866d..e1006bb90 100644 --- a/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/BrandsController.cs +++ b/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/BrandsController.cs @@ -26,7 +26,7 @@ public async Task GetById(int id) var brand = await _mediator.Send(new GetBrandByIdQuery() { Id = id }); return Ok(brand); } - + [Authorize(Policy = Permissions.Brands.Create)] [HttpPost] public async Task Post(AddEditBrandCommand command) diff --git a/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/ProductsController.cs b/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/ProductsController.cs index 844c707e8..256ccaf4d 100644 --- a/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/ProductsController.cs +++ b/BlazorHero.CleanArchitecture/Server/Controllers/v1/Catalog/ProductsController.cs @@ -26,6 +26,7 @@ public async Task GetProductImageAsync(int id) var result = await _mediator.Send(new GetProductImageQuery(id)); return Ok(result); } + [Authorize(Policy = Permissions.Products.Create)] [HttpPost] public async Task Post(AddEditProductCommand command) diff --git a/BlazorHero.CleanArchitecture/Server/Controllers/v1/DashboardController.cs b/BlazorHero.CleanArchitecture/Server/Controllers/v1/DashboardController.cs index 6e23c7a31..907d132f7 100644 --- a/BlazorHero.CleanArchitecture/Server/Controllers/v1/DashboardController.cs +++ b/BlazorHero.CleanArchitecture/Server/Controllers/v1/DashboardController.cs @@ -1,10 +1,6 @@ using BlazorHero.CleanArchitecture.Application.Features.Dashboard.GetData; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; namespace BlazorHero.CleanArchitecture.Server.Controllers.v1 @@ -20,4 +16,4 @@ public async Task GetDataAsync() return Ok(result); } } -} +} \ No newline at end of file diff --git a/BlazorHero.CleanArchitecture/Server/appsettings.Development.json b/BlazorHero.CleanArchitecture/Server/appsettings.Development.json index d524449fd..5eb541ed0 100644 --- a/BlazorHero.CleanArchitecture/Server/appsettings.Development.json +++ b/BlazorHero.CleanArchitecture/Server/appsettings.Development.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=BlazorHero.CleanArchitectureClone1;Integrated Security=True;MultipleActiveResultSets=True" + "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=BlazorHero.CleanArchitecture;Integrated Security=True;MultipleActiveResultSets=True" }, "Logging": { "LogLevel": { diff --git a/BlazorHero.CleanArchitecture/Server/appsettings.json b/BlazorHero.CleanArchitecture/Server/appsettings.json index ae4d05768..f2973b7a0 100644 --- a/BlazorHero.CleanArchitecture/Server/appsettings.json +++ b/BlazorHero.CleanArchitecture/Server/appsettings.json @@ -12,7 +12,7 @@ "Secret": "S0M3RAN0MS3CR3T!1!MAG1C!1!" }, "ConnectionStrings": { - "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=BlazorHero.CleanArchitectureClone1;Integrated Security=True;MultipleActiveResultSets=True" + "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=BlazorHero.CleanArchitecture;Integrated Security=True;MultipleActiveResultSets=True" }, "MailConfiguration": { "From": "info@codewithmukesh.com",