diff --git a/FaKrosnoApi/Controllers/HangfireJobsController.cs b/FaKrosnoApi/Controllers/HangfireJobsController.cs index b3cc7ee..54725ed 100644 --- a/FaKrosnoApi/Controllers/HangfireJobsController.cs +++ b/FaKrosnoApi/Controllers/HangfireJobsController.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using FaKrosnoApi.Models; using Hangfire; using Hangfire.Storage; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using OrdersManagementDataModel.Dtos; using OrdersManagementDataModel.Services; @@ -10,7 +11,10 @@ namespace FaKrosnoApi.Controllers; [ApiController] [Route("api/[controller]")] -public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager recurringJobManager, ITaskSchedulerService service) : Controller +public class HangfireJobsController( + JobStorage jobStorage, + IRecurringJobManager recurringJobManager, + ITaskSchedulerService service) : Controller { [HttpGet("GetJobsToRun")] public async Task>> GetJobsToRun() @@ -25,7 +29,7 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager foreach (var recurringJob in recurringJobs) { TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id); - + if (taskScheduler != null) { jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path, @@ -36,8 +40,8 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager return Ok(jobsToRun); } - - [HttpPost("RunJobs")] + + [HttpPost("run")] public async Task RunJobs() { var jobsToRun = (await GetJobsToRun()).Value?.ToList(); @@ -58,8 +62,8 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON."); } - - [HttpPost("AddTask")] + + [HttpPost("add")] public async Task AddTask([FromBody] TaskSchedulerDto taskSchedulerDto) { var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler @@ -83,9 +87,11 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager return Ok("Zadanie zostało dodane."); } - [HttpPost("DeleteTask")] + [HttpPost("delete")] public async Task DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto) { + var taskSchedulerByTaskName = await service.GetTaskSchedulerByTaskName(taskSchedulerDto.Name); + Console.WriteLine(taskSchedulerByTaskName.RowPointer); int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer); if (result == 0) @@ -98,21 +104,35 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager return Ok("Zadanie zostało usunięte."); } - [HttpGet("GetTasks")] + [HttpGet] public async Task>> GetTasks() { var tasks = await service.GetTaskSchedulers(); - + foreach (TaskSchedulerDto taskSchedulerDto in tasks) { var job = GetJob(taskSchedulerDto.Name); taskSchedulerDto.LastExecution = job?.LastExecution; taskSchedulerDto.NextExecution = job?.NextExecution; } - + return Ok(tasks); } + [HttpGet("by-name")] + public async Task> GetTaskSchedulerByTaskName([FromQuery] string name) + { + var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name); + + if (taskSchedulerDto == null) return NotFound(); + + var job = GetJob(taskSchedulerDto.Name); + taskSchedulerDto.LastExecution = job?.LastExecution; + taskSchedulerDto.NextExecution = job?.NextExecution; + + return Ok(taskSchedulerDto); + } + private RecurringJobDto? GetJob(string jobId) { using IStorageConnection? connection = jobStorage.GetConnection(); diff --git a/FaKrosnoApi/Controllers/ScheduleJobController.cs b/FaKrosnoApi/Controllers/ScheduleJobController.cs index ae259c2..4723aac 100644 --- a/FaKrosnoApi/Controllers/ScheduleJobController.cs +++ b/FaKrosnoApi/Controllers/ScheduleJobController.cs @@ -1,4 +1,5 @@ using FaKrosnoApi.Services; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace FaKrosnoApi.Controllers; diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index da0e9d8..d051a14 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -51,13 +51,11 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); -// Konfiguracja NSwag z obsługą Bearer Token builder.Services.AddOpenApiDocument(config => { config.Title = "FaKrosnoApi"; config.Version = "v1"; - // Dodaj definicję zabezpieczeń Bearer Token config.AddSecurity("Bearer", new OpenApiSecurityScheme { Name = "Authorization", @@ -68,23 +66,22 @@ builder.Services.AddOpenApiDocument(config => Description = "Wprowadź token JWT w formacie: Bearer {token}" }); - // Zastosuj zabezpieczenia globalnie config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer")); }); -// builder.Services.AddHangfire(config => config -// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) -// .UseSimpleAssemblyNameTypeSerializer() -// .UseRecommendedSerializerSettings() -// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions -// { -// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), -// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), -// QueuePollInterval = TimeSpan.Zero, -// UseRecommendedIsolationLevel = true, -// DisableGlobalLocks = true -// })); -// builder.Services.AddHangfireServer(); +builder.Services.AddHangfire(config => config + .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) + .UseSimpleAssemblyNameTypeSerializer() + .UseRecommendedSerializerSettings() + .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions + { + CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), + SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), + QueuePollInterval = TimeSpan.Zero, + UseRecommendedIsolationLevel = true, + DisableGlobalLocks = true + })); +builder.Services.AddHangfireServer(); builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile), typeof(OrdersManagementMappingProfile)); @@ -116,6 +113,6 @@ app.UseAuthorization(); app.MapControllers(); -// app.UseHangfireDashboard(); +app.UseHangfireDashboard(); app.Run(); diff --git a/FaKrosnoApi/appsettings.json b/FaKrosnoApi/appsettings.json index a907f3a..0c30353 100644 --- a/FaKrosnoApi/appsettings.json +++ b/FaKrosnoApi/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { - "FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosno;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", - "SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PROD_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", + "FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosnotest;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", + "SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PRODTEST_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", "OrdersManagementConnection": "Server=192.168.0.7;Database=OrdersManagement;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true" }, "Logging": { diff --git a/OrdersManagement/Components/App.razor b/OrdersManagement/Components/App.razor index 9b043e6..3459ba0 100644 --- a/OrdersManagement/Components/App.razor +++ b/OrdersManagement/Components/App.razor @@ -1,4 +1,5 @@ @using Microsoft.AspNetCore.Components.Authorization +@using OrdersManagement.Components.Layout @@ -18,7 +19,22 @@ - + + + + + + +

Brak autoryzacji

+

Zaloguj się

+
+
+
+ +

Strona nie znaleziona.

+
+
+
diff --git a/OrdersManagement/Components/Layout/MainLayout.razor b/OrdersManagement/Components/Layout/MainLayout.razor index f7b144f..a300bcd 100644 --- a/OrdersManagement/Components/Layout/MainLayout.razor +++ b/OrdersManagement/Components/Layout/MainLayout.razor @@ -1,50 +1,87 @@ -@using Syncfusion.Blazor.Navigations -@using Syncfusion.Blazor.SplitButtons -@using Orientation = Syncfusion.Blazor.Navigations.Orientation -@inject NavigationManager NavigationManager -@inherits LayoutComponentBase +@inherits LayoutComponentBase -
+@using System.Security.Claims +@using Microsoft.AspNetCore.Components.Authorization +@using Syncfusion.Blazor.Navigations +@using static Syncfusion.Blazor.Navigations.Orientation +@using Syncfusion.Blazor.Buttons +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider AuthenticationStateProvider + +
-
+
Icon - FA Krosno Manager +

FA Krosno Manager

+
+
+ @if (IsAuthenticated) + { + Jesteś zalogowany jako @UserName + Wyloguj + } + else + { + Zaloguj + }
- About
-
- - - +
+ + + + + + @if (UserName == "pkus") + { + + + + + + + } + +
@Body
+
+ FA Krosno Manager © @(DateTime.Now.Year) +
- @code { - private List MenuItems { get; set; } = new(); + private bool IsAuthenticated { get; set; } + private string UserName { get; set; } = string.Empty; protected override void OnInitialized() { - MenuItems = new List - { - new() { Text = "Zamówienia DELFOR", Url = "/ScheduleOrders", IconCss = "fa-solid fa-landmark" }, - new() { Text = "Zamówienia klienta EDI", Url = "/EdiCustomerOrders", IconCss = "fa-solid fa-list-check" }, - new() { Text = "Zamówienia klienta", Url = "/CustomerOrders", IconCss = "fa-solid fa-database" } - }; + ClaimsPrincipal currentUser = AuthenticationStateProvider.GetCurrentUser(); + IsAuthenticated = currentUser.Identity?.IsAuthenticated == true; + UserName = currentUser.Identity?.Name ?? "Nieznany użytkownik"; + + AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged; } - private void OnMenuItemSelected(MenuEventArgs args) + private async void OnAuthenticationStateChanged(Task task) { - NavigationManager.NavigateTo(args.Item.Url); + var authState = await task; + IsAuthenticated = authState.User.Identity?.IsAuthenticated ?? false; + UserName = IsAuthenticated ? authState.User.Identity?.Name ?? "Nieznany użytkownik" : string.Empty; + StateHasChanged(); + } + + private void Logout() + { + NavigationManager.NavigateTo("/"); } } diff --git a/OrdersManagement/Components/Layout/NavMenu.razor b/OrdersManagement/Components/Layout/NavMenu.razor deleted file mode 100644 index f8d4efd..0000000 --- a/OrdersManagement/Components/Layout/NavMenu.razor +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - diff --git a/OrdersManagement/Components/Layout/NavMenu.razor.css b/OrdersManagement/Components/Layout/NavMenu.razor.css deleted file mode 100644 index 4e15395..0000000 --- a/OrdersManagement/Components/Layout/NavMenu.razor.css +++ /dev/null @@ -1,105 +0,0 @@ -.navbar-toggler { - appearance: none; - cursor: pointer; - width: 3.5rem; - height: 2.5rem; - color: white; - position: absolute; - top: 0.5rem; - right: 1rem; - border: 1px solid rgba(255, 255, 255, 0.1); - background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1); -} - -.navbar-toggler:checked { - background-color: rgba(255, 255, 255, 0.5); -} - -.top-row { - height: 3.5rem; - background-color: rgba(0,0,0,0.4); -} - -.navbar-brand { - font-size: 1.1rem; -} - -.bi { - display: inline-block; - position: relative; - width: 1.25rem; - height: 1.25rem; - margin-right: 0.75rem; - top: -1px; - background-size: cover; -} - -.bi-house-door-fill-nav-menu { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E"); -} - -.bi-plus-square-fill-nav-menu { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E"); -} - -.bi-list-nested-nav-menu { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E"); -} - -.nav-item { - font-size: 0.9rem; - padding-bottom: 0.5rem; -} - - .nav-item:first-of-type { - padding-top: 1rem; - } - - .nav-item:last-of-type { - padding-bottom: 1rem; - } - - .nav-item ::deep .nav-link { - color: #d7d7d7; - background: none; - border: none; - border-radius: 4px; - height: 3rem; - display: flex; - align-items: center; - line-height: 3rem; - width: 100%; - } - -.nav-item ::deep a.active { - background-color: rgba(255,255,255,0.37); - color: white; -} - -.nav-item ::deep .nav-link:hover { - background-color: rgba(255,255,255,0.1); - color: white; -} - -.nav-scrollable { - display: none; -} - -.navbar-toggler:checked ~ .nav-scrollable { - display: block; -} - -@media (min-width: 641px) { - .navbar-toggler { - display: none; - } - - .nav-scrollable { - /* Never collapse the sidebar for wide screens */ - display: block; - - /* Allow sidebar to scroll for tall menus */ - height: calc(100vh - 3.5rem); - overflow-y: auto; - } -} diff --git a/OrdersManagement/Components/Pages/Admin/Scheduler.razor b/OrdersManagement/Components/Pages/Admin/Scheduler.razor index eecb049..d2d8fd9 100644 --- a/OrdersManagement/Components/Pages/Admin/Scheduler.razor +++ b/OrdersManagement/Components/Pages/Admin/Scheduler.razor @@ -1,30 +1,77 @@ @page "/Admin/Scheduler" + +@attribute [Authorize] + +@using System.Security.Claims +@using Microsoft.AspNetCore.Authorization @using OrdersManagementDataModel.Dtos @using Syncfusion.Blazor.Grids @using Action = Syncfusion.Blazor.Grids.Action -@inject HangfireService HangfireService +@using Syncfusion.Blazor.Cards -

Zarządzanie Zadaniami

-
- - - - - - - - - - - - +@inject HangfireService HangfireService +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +
+ + +

Zarządzanie Zadaniami

+
+ + + + + + + + + + + + + + + + + + + FA Krosno Manager © @(DateTime.Now.Year) + +
+
@code { private List Tasks { get; set; } = new(); - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { - await LoadTasks(); + if (firstRender) + { + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + await LoadTasks(); + StateHasChanged(); + } + } } public async Task OnActionBegin(ActionEventArgs args) @@ -65,4 +112,5 @@ break; } } + } \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/Admin/Users/UsersManager.razor b/OrdersManagement/Components/Pages/Admin/Users/UsersManager.razor deleted file mode 100644 index 24ed19e..0000000 --- a/OrdersManagement/Components/Pages/Admin/Users/UsersManager.razor +++ /dev/null @@ -1,171 +0,0 @@ -@page "/admin/UsersManager" - -@using OrdersManagementDataModel.Dtos -@using Syncfusion.Blazor.Grids -@using Action = Syncfusion.Blazor.Grids.Action -@using UserService = OrdersManagement.Services.UserService -@inject UserService UserService -@inject RoleService RoleService -@inject FunctionService FunctionService - -
-
Użytkownicy
- - - - - - - - - - - - - § -
-
Role
- - - - - - - - -
-
Funkcje
- - - - - - - - - -
- -@code { - private List UserList { get; set; } = new(); - private List Roles { get; set; } = new(); - private List Functions { get; set; } = new(); - - protected override async Task OnInitializedAsync() - { - await LoadUsers(); - await LoadRoles(); - await LoadFunctions(); - } - - private async Task LoadUsers() - { - UserList = (await UserService.GetUsersAsync() ?? Array.Empty()).ToList(); - } - - private async Task LoadRoles() - { - Roles = (await RoleService.GetRolesAsync() ?? Array.Empty()).ToList(); - } - - private async Task LoadFunctions() - { - Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty()).ToList(); - } - - private async Task UserActionBegin(ActionEventArgs args) - { - if (args.RequestType.Equals(Action.Delete)) - { - await UserService.DeleteUserAsync(args.Data.RowPointer); - } - else if (args.RequestType.Equals(Action.Add)) - { - args.Data.RowPointer = Guid.NewGuid(); - } - } - - private async Task UserActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - await LoadUsers(); - break; - case Action.Add: - await UserService.AddUserAsync(args.Data); - await LoadUsers(); - break; - case Action.Save: - await UserService.UpdateUserAsync(args.Data); - await LoadUsers(); - break; - } - } - - private async Task RoleActionBegin(ActionEventArgs args) - { - if (args.RequestType.Equals(Action.Delete)) - { - await RoleService.DeleteRoleAsync(args.Data.RowPointer); - } - else if (args.RequestType.Equals(Action.Add)) - { - args.Data.RowPointer = Guid.NewGuid(); - } - } - - private async Task RoleActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - await LoadRoles(); - break; - case Action.Add: - await RoleService.AddRoleAsync(args.Data); - await LoadRoles(); - break; - case Action.Save: - await RoleService.UpdateRoleAsync(args.Data); - await LoadRoles(); - break; - } - } - - private async Task FunctionActionBegin(ActionEventArgs args) - { - if (args.RequestType.Equals(Action.Delete)) - { - await FunctionService.DeleteFunctionAsync(args.Data.RowPointer); - } - else if (args.RequestType.Equals(Action.Add)) - { - args.Data.RowPointer = Guid.NewGuid(); - } - } - - private async Task FunctionActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - await LoadFunctions(); - break; - case Action.Add: - await FunctionService.AddFunctionAsync(args.Data); - await LoadFunctions(); - break; - case Action.Save: - await FunctionService.UpdateFunctionAsync(args.Data); - await LoadFunctions(); - break; - } - } -} \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/Admin/UsersManager.razor b/OrdersManagement/Components/Pages/Admin/UsersManager.razor new file mode 100644 index 0000000..9bfb8d7 --- /dev/null +++ b/OrdersManagement/Components/Pages/Admin/UsersManager.razor @@ -0,0 +1,298 @@ +@page "/admin/UsersManager" + +@attribute [Authorize] + +@using System.Security.Claims +@using Microsoft.AspNetCore.Authorization +@using OrdersManagementDataModel.Dtos +@using Syncfusion.Blazor.Grids +@using Action = Syncfusion.Blazor.Grids.Action +@using UserService = OrdersManagement.Services.UserService +@using Syncfusion.Blazor.Cards +@using Syncfusion.Blazor.Popups +@using Syncfusion.Blazor.Buttons +@inject UserService UserService +@inject RoleService RoleService +@inject FunctionService FunctionService +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +
+ + +

Zarządzanie Użytkownikami i Rolami

+
+ +
Użytkownicy
+ + + + + + + + + + + + + + + + + + + + +
Role
+ + + + + + + + + + + + +
Funkcje
+ + + + + + + + + + + + + + + + +

Użytkownik @Login został dodany pomyślnie!

+

Hasło tymczasowe: @TempPassword

+
+
+ + + +
+
+ + FA Krosno Manager © @(DateTime.Now.Year) + +
+
+ +@code { + private List UserList { get; set; } = new(); + private List Roles { get; set; } = new(); + private List Functions { get; set; } = new(); + + private bool Visibility { get; set; } + + private string Login { get; set; } = string.Empty; + private string TempPassword { get; set; } = string.Empty; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + Visibility = false; + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + await LoadUsers(); + await LoadRoles(); + //await LoadFunctions(); + StateHasChanged(); + } + } + } + + private async Task LoadUsers() + { + UserList = (await UserService.GetUsersAsync() ?? Array.Empty()).ToList(); + } + + private async Task LoadRoles() + { + Roles = (await RoleService.GetRolesAsync() ?? Array.Empty()).ToList(); + } + + private async Task LoadFunctions() + { + Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty()).ToList(); + } + + public async Task ResetPassword(UserDto? user) + { + if(user == null) return; + + TempPassword = Guid.NewGuid().ToString().Substring(0, 8); + Login = user.Login; + + string passwordHash = BCrypt.Net.BCrypt.HashPassword(TempPassword); + + user.PasswordHash = passwordHash; + user.IsTemporaryPassword = true; + + await UserService.UpdateUserAsync(user); + await LoadUsers(); + + Visibility = true; + } + + private async Task UserActionBegin(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await UserService.DeleteUserAsync(args.Data.RowPointer); + break; + case Action.Add: + args.Data.RowPointer = Guid.NewGuid(); + args.Data.CreatedDate = DateTime.Now; + args.Data.IsActive = true; + break; + } + } + + private async Task UserActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadUsers(); + break; + case Action.Save when args.Data.Id == 0: + UserDto? user = args.Data; + TempPassword = Guid.NewGuid().ToString().Substring(0, 8); + Login = user.Login; + + string? passwordHash = BCrypt.Net.BCrypt.HashPassword(TempPassword); + + user.PasswordHash = passwordHash; + user.IsTemporaryPassword = true; + user.ActiveFrom = DateTime.Now; + user.CreatedDate = DateTime.Now; + + await UserService.AddUserAsync(user); + await LoadUsers(); + + Visibility = true; + break; + case Action.Save when args.Data.Id != 0: + await UserService.UpdateUserAsync(args.Data); + await LoadUsers(); + break; + } + } + + private async Task RoleActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await RoleService.DeleteRoleAsync(args.Data.RowPointer); + } + else if (args.RequestType.Equals(Action.Add)) + { + args.Data.RowPointer = Guid.NewGuid(); + } + } + + private async Task RoleActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadRoles(); + break; + case Action.Save when args.Data.Id == 0: + await RoleService.AddRoleAsync(args.Data); + await LoadUsers(); + break; + case Action.Save when args.Data.Id != 0: + await RoleService.UpdateRoleAsync(args.Data); + await LoadRoles(); + break; + } + } + + private async Task FunctionActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await FunctionService.DeleteFunctionAsync(args.Data.RowPointer); + } + else if (args.RequestType.Equals(Action.Add)) + { + args.Data.RowPointer = Guid.NewGuid(); + } + } + + private async Task FunctionActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadFunctions(); + break; + case Action.Save when args.Data.Id == 0: + await FunctionService.AddFunctionAsync(args.Data); + await LoadFunctions(); + break; + case Action.Save when args.Data.Id != 0: + await FunctionService.UpdateFunctionAsync(args.Data); + await LoadFunctions(); + break; + } + } + + private void HideModal() + { + Visibility = false; + } +} \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/CustomerOrder.razor b/OrdersManagement/Components/Pages/CustomerOrder.razor index cf1dcad..bfb8c35 100644 --- a/OrdersManagement/Components/Pages/CustomerOrder.razor +++ b/OrdersManagement/Components/Pages/CustomerOrder.razor @@ -1,204 +1,198 @@ @page "/CustomerOrder/{CustomerOrderId:guid}" -@rendermode InteractiveServer +@attribute [Authorize] @inject CustomerOrderService CustomerOrderService @inject ScheduleOrderService ScheduleOrderService +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +@using System.Security.Claims +@using Microsoft.AspNetCore.Authorization @using SytelineSaAppEfDataModel.Dtos @using OrdersManagement.Components.Pages.Shared @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.Cards +@using Syncfusion.Blazor.Buttons +@using SelectionType = Syncfusion.Blazor.Grids.SelectionType @inherits LayoutComponentBase -
-
Zamówienie klienta nr @CustomerOrderDto?.CoNum
- +
+ + +

Zamówienie klienta nr @(CustomerOrderDto?.CoNum ?? "Brak numeru")

+
-
-
- Numer Zamówienia: @CustomerOrderDto?.CoNum
- Numer Zamówienia Klienta: @CustomerOrderDto?.CustPo
- Klient: @CustomerOrderDto?.CustNum
- Numer Odbiorcy: @CustomerOrderDto?.CustSeq
- Kontakt: @CustomerOrderDto?.Contact
- Telefon: @CustomerOrderDto?.Phone
- Data Zamówienia: @CustomerOrderDto?.OrderDate.ToString("yyyy-MM-dd HH:mm:ss")
- Warunki: @CustomerOrderDto?.TermsCode
- Wartość Brutto: @(CustomerOrderDto?.Price?.ToString("F2") ?? "N/A")
- Status: @CustomerOrderDto?.TranslatedStatus
-
-
- Magazyn: @CustomerOrderDto?.Whse
- VAT: @CustomerOrderDto?.FrtTaxCode1
- Typ Odbiorcy: @CustomerOrderDto?.EndUserType
- Kurs Wymiany: @(CustomerOrderDto?.ExchRate?.ToString("F4") ?? "N/A")
- Gate: @CustomerOrderDto?.Uf_FKR_EDI_Gate
- RecipientCode: @CustomerOrderDto?.Uf_FKR_EDI_RecipientCode
- SelletCode: @CustomerOrderDto?.Uf_FKR_EDI_SellerCode
- SenderCode: @CustomerOrderDto?.Uf_FKR_EDI_SenderCode
- BuyerCode: @CustomerOrderDto?.Uf_FKR_EDI_BuyerCode
- Typ Dokumentu: @CustomerOrderDto?.Uf_DocType
+ + +
+
+ Numer Zamówienia: @CustomerOrderDto?.CoNum
+ Numer Zamówienia Klienta: @CustomerOrderDto?.CustPo
+ Klient: @CustomerOrderDto?.CustNum
+ Numer Odbiorcy: @CustomerOrderDto?.CustSeq
+ Kontakt: @CustomerOrderDto?.Contact
+ Telefon: @CustomerOrderDto?.Phone
+ Data Zamówienia: @CustomerOrderDto?.OrderDate.ToString("yyyy-MM-dd HH:mm:ss")
+ Warunki: @CustomerOrderDto?.TermsCode
+ Wartość Brutto: @(CustomerOrderDto?.Price?.ToString("F2") ?? "N/A")
+ Status: @CustomerOrderDto?.TranslatedStatus
+
+
+ Magazyn: @CustomerOrderDto?.Whse
+ VAT: @CustomerOrderDto?.FrtTaxCode1
+ Typ Odbiorcy: @CustomerOrderDto?.EndUserType
+ Kurs Wymiany: @(CustomerOrderDto?.ExchRate?.ToString("F4") ?? "N/A")
+ Gate: @CustomerOrderDto?.Uf_FKR_EDI_Gate
+ RecipientCode: @CustomerOrderDto?.Uf_FKR_EDI_RecipientCode
+ SellerCode: @CustomerOrderDto?.Uf_FKR_EDI_SellerCode
+ SenderCode: @CustomerOrderDto?.Uf_FKR_EDI_SenderCode
+ BuyerCode: @CustomerOrderDto?.Uf_FKR_EDI_BuyerCode
+ Typ Dokumentu: @CustomerOrderDto?.Uf_DocType
+
+
+
+
+ +
+
+ @_text
+ + @if (_isVisible) + { +
Zamówienie DELFOR do zamówienia @(CustomerOrderDto?.CoNum ?? "Brak numeru")
+ + } + +
Indeksy
+ + + + @{ + var order = context as CustomerOrderLineDto; + + +
+
Szczegóły
+
+ Numer zamówienia:@order?.CoNum
+ Linia:@order?.CoLine
+ Pozycja:@order?.Item
+ Pozycja Klienta:@order?.CustItem
+ Opis:@order?.Description
+ Łączna Ilość:@order?.BlanketQty.ToString("F2")
+ Status:@order?.TranslatedStatus
+
+
+ Cena:@(order?.ContPrice?.ToString("F2") ?? "N/A")
+ Ważne Od:@(order?.EffDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ J/M:@order?.UM
+ BoxType:@order?.Uf_FKR_EDI_BLN_BoxType
+ Address:@order?.Uf_FKR_EDI_BLN_Address
+ FinalDestination:@order?.Uf_FKR_EDI_BLN_FinalDestination
+ QtyPerBox:@(order?.Uf_FKR_EDI_BLN_QtyPerBox?.ToString() ?? "N/A") +
+
+
+
+ } +
+
+ + + + + + + + + + + + + + +
+ + @if (_isVisibleCustomerOrderLine) + { +
Harmonogramy
+ + + + @{ + var detailLineItem = context as CustomerOrderLineItemDto; + + +
+
Szczegóły
+
+ Numer Zamówienia:@detailLineItem?.CoNum
+ Linia:@detailLineItem?.CoLine
+ Zwolnienie:@detailLineItem?.CoRelease
+ Pozycja:@detailLineItem?.Item
+ Pozycja Klienta:@detailLineItem?.CustItem
+ Łączna Ilość Sztuk:@(detailLineItem?.QtyOrdered.ToString("F2") ?? "N/A")
+ Cena:@(detailLineItem?.Price.ToString("F2") ?? "N/A")
+ Data Wykonania:@(detailLineItem?.DueDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Data Rejestracji:@(detailLineItem?.ReleaseDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Magazyn:@detailLineItem?.Whse
+ Typ Documentu:@detailLineItem?.Uf_FKR_EDI_ITEM_DocumentType
+
+
+ Kod VAT:@detailLineItem?.TaxCode1
+ J/M:@detailLineItem?.UM
+ Numer Klienta:@detailLineItem?.CoCustNum
+ Opis:@detailLineItem?.Description
+ Status:@detailLineItem?.TranslatedStatus
+ RoutingCode:@detailLineItem?.Uf_FKR_EDI_ITEM_RoutingCode
+ DeliveryCallNumber:@detailLineItem?.Uf_FKR_EDI_ITEM_DeliveryCallNum
+ UnloadingPoint:@detailLineItem?.Uf_LOC_11_UnloadingPoint
+ DestinationPoint:@detailLineItem?.Uf_LOC_159_DestinationPoint
+ PalletCode:@detailLineItem?.Uf_FKR_EDI_ITEM_PalletCode
+
+
+
+
+ } +
+
+ + + + + + + + + + + + +
+ } + + FA Krosno Manager © @(DateTime.Now.Year) + -
-
-
- -
-
-
- @if (_isVisible) - { -
-
Zamówienie DELFOR do zamówienia @CustomerOrderDto?.CoNum
-
-
-
- -
-
- } -
Indeksy
- - - - @{ - var order = context as CustomerOrderLineDto; - - -
-
Szczegóły
-
- Numer zamówienia:@order?.CoNum
- Linia:@order?.CoLine
- Pozycja:@order?.Item
- Pozycja Klienta:@order?.CustItem
- Opis:@order?.Description
- Łączna Ilość:@order?.BlanketQty.ToString("F2")
- Status:@order?.TranslatedStatus
-
-
- Cena:@(order?.ContPrice?.ToString("F2") ?? "N/A")
- Ważne Od:@(order?.EffDate?.ToString("dd.MM.yyyy") ?? "N/A")
- J/M:@order?.UM
- BoxType:@order?.Uf_FKR_EDI_BLN_BoxType
- Address:@order?.Uf_FKR_EDI_BLN_Address
- FinalDestination:@order?.Uf_FKR_EDI_BLN_FinalDestination
- QtyPerBox:@(order?.Uf_FKR_EDI_BLN_QtyPerBox?.ToString() ?? "N/A") -
-
-
-
- } -
-
- - - - - - - - - - - - - - -
- @if (_isVisibleCustomerOrderLine) - { -
-
Harmonogramy
- - - - @{ - var detailLineItem = context as CustomerOrderLineItemDto; - - -
-
Szczegóły
-
- Numer Zamówienia:@detailLineItem?.CoNum
- Linia:@detailLineItem?.CoLine
- Zwolnienie:@detailLineItem?.CoRelease
- Pozycja:@detailLineItem?.Item
- Pozycja Klienta:@detailLineItem?.CustItem
- Łączna Ilość - Sztuk:@(detailLineItem?.QtyOrdered.ToString("F2") ?? "N/A")
- Cena:@(detailLineItem?.Price.ToString("F2") ?? "N/A")
- Data - Wykonania:@(detailLineItem?.DueDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Data - Rejestracji:@(detailLineItem?.ReleaseDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Magazyn:@detailLineItem?.Whse
- Typ - Documentu:@detailLineItem?.Uf_FKR_EDI_ITEM_DocumentType
-
-
- Kod VAT:@detailLineItem?.TaxCode1
- J/M:@detailLineItem?.UM
- Numer Klienta:@detailLineItem?.CoCustNum
- Opis:@detailLineItem?.Description
- Status:@detailLineItem?.TranslatedStatus
- RoutingCode:@detailLineItem?.Uf_FKR_EDI_ITEM_RoutingCode
- DeliveryCallNumber:@detailLineItem?.Uf_FKR_EDI_ITEM_DeliveryCallNum
- UnloadingPoint:@detailLineItem?.Uf_LOC_11_UnloadingPoint
- DestinationPoint:@detailLineItem?.Uf_LOC_159_DestinationPoint
- PalletCode:@detailLineItem?.Uf_FKR_EDI_ITEM_PalletCode
-
-
-
-
- } -
-
- - - - - - - - - - - - -
- }
@code { @@ -221,18 +215,7 @@ private bool _isVisible = true; private string _text = "Pokaż powiązane zamówienia DELFOR"; - - protected override async Task OnInitializedAsync() - { - CustomerOrderDto? customerOrder = await CustomerOrderService.GetCustomerOrderAsync(CustomerOrderId); - - if (customerOrder != null) - { - CustomerOrderDto = customerOrder; - _customerOrderLines = CustomerOrderDto.CustomerOrderLines.ToList() ?? []; - } - } - + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -240,6 +223,23 @@ await SetGridRef(_gridRef); StateHasChanged(); _isVisible = false; + + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false) + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + CustomerOrderDto? customerOrder = await CustomerOrderService.GetCustomerOrderAsync(CustomerOrderId); + + if (customerOrder != null) + { + CustomerOrderDto = customerOrder; + _customerOrderLines = CustomerOrderDto.CustomerOrderLines.ToList() ?? []; + } + } } } diff --git a/OrdersManagement/Components/Pages/CustomerOrders.razor b/OrdersManagement/Components/Pages/CustomerOrders.razor index 354a824..6ac06dd 100644 --- a/OrdersManagement/Components/Pages/CustomerOrders.razor +++ b/OrdersManagement/Components/Pages/CustomerOrders.razor @@ -1,86 +1,110 @@ @page "/CustomerOrders" -@rendermode InteractiveServer +@attribute [Authorize] @inject CustomerOrderService CustomerOrderService @inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +@using System.Security.Claims +@using Microsoft.AspNetCore.Authorization @using SytelineSaAppEfDataModel.Dtos @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.Cards @inherits LayoutComponentBase -
-
Zamówienia Klienta
- - - - @{ - var order = context as CustomerOrderDto; - - -
-
- Numer Zamówienia: @order?.CoNum
- Numer Zamówienia Klienta: @order?.CustPo
- Klient: @order?.CustNum
- Numer Odbiorcy: @order?.CustSeq
- Kontakt: @order?.Contact
- Telefon: @order?.Phone
- Data Zamówienia: - @order?.OrderDate.ToString("yyyy-MM-dd HH:mm:ss")
- Warunki: @order?.TermsCode
- Wartość Brutto: @(order?.Price?.ToString("F2") ?? "N/A")
- Status: @order?.TranslatedStatus
-
-
- Magazyn: @order?.Whse
- VAT: @order?.FrtTaxCode1
- Typ Odbiorcy: @order?.EndUserType
- Kurs Wymiany: @(order?.ExchRate?.ToString("F4") ?? "N/A")
- Gate: @order?.Uf_FKR_EDI_Gate
- RecipientCode: @order?.Uf_FKR_EDI_RecipientCode
- SelletCode: @order?.Uf_FKR_EDI_SellerCode
- SenderCode: @order?.Uf_FKR_EDI_SenderCode
- BuyerCode: @order?.Uf_FKR_EDI_BuyerCode
- Typ Dokumentu: @order?.Uf_DocType
-
-
-
-
- } -
-
- - - - - - - - - - - - -
+
+ + +

Zamówienia Klienta

+
+ + + + + @{ + var order = context as CustomerOrderDto; + + +
+
+ Numer Zamówienia: @order?.CoNum
+ Numer Zamówienia Klienta: @order?.CustPo
+ Klient: @order?.CustNum
+ Numer Odbiorcy: @order?.CustSeq
+ Kontakt: @order?.Contact
+ Telefon: @order?.Phone
+ Data Zamówienia: + @order?.OrderDate.ToString("yyyy-MM-dd HH:mm:ss")
+ Warunki: @order?.TermsCode
+ Wartość Brutto: @(order?.Price?.ToString("F2") ?? "N/A")
+ Status: @order?.TranslatedStatus
+
+
+ Magazyn: @order?.Whse
+ VAT: @order?.FrtTaxCode1
+ Typ Odbiorcy: @order?.EndUserType
+ Kurs Wymiany: @(order?.ExchRate?.ToString("F4") ?? "N/A")
+ Gate: @order?.Uf_FKR_EDI_Gate
+ RecipientCode: @order?.Uf_FKR_EDI_RecipientCode
+ SellerCode: @order?.Uf_FKR_EDI_SellerCode
+ SenderCode: @order?.Uf_FKR_EDI_SenderCode
+ BuyerCode: @order?.Uf_FKR_EDI_BuyerCode
+ Typ Dokumentu: @order?.Uf_DocType
+
+
+
+
+ } +
+
+ + + + + + + + + + + + +
+
+ + FA Krosno Manager © @(DateTime.Now.Year) + +
@code { private IEnumerable? _customerOrders; - - protected override async Task OnInitializedAsync() + + protected override async Task OnAfterRenderAsync(bool firstRender) { - _customerOrders = await CustomerOrderService.GetCustomerOrdersAsync() ?? new List(); - _customerOrders = _customerOrders.OrderByDescending(x => x.CreateDate).ToList(); + if (firstRender) + { + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - StateHasChanged(); + if (currentUser.Identity?.IsAuthenticated == false) + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + _customerOrders = await CustomerOrderService.GetCustomerOrdersAsync() ?? new List(); + _customerOrders = _customerOrders.OrderByDescending(x => x.CreateDate).ToList(); + + StateHasChanged(); + } + } } private void OnRowDoubleClick(RecordDoubleClickEventArgs obj) diff --git a/OrdersManagement/Components/Pages/EdiCustomerOrder.razor b/OrdersManagement/Components/Pages/EdiCustomerOrder.razor index 43159fa..76ba82b 100644 --- a/OrdersManagement/Components/Pages/EdiCustomerOrder.razor +++ b/OrdersManagement/Components/Pages/EdiCustomerOrder.razor @@ -1,192 +1,182 @@ @page "/EdiCustomerOrder/{CustomerOrderId:guid}" -@rendermode InteractiveServer +@attribute [Authorize] @inject EdiCustomerOrderService EdiCustomerOrderService +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +@using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using SytelineSaAppEfDataModel.Dtos @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.Cards + @inherits LayoutComponentBase -
-
Zamówienie klienta nr @EdiCustomerOrderDto?.CustomerOrderNumber
- +
+ + +

Zamówienie klienta EDI nr @(EdiCustomerOrderDto?.CustomerOrderNumber ?? "Brak numeru")

+
-
-
- Numer zamówienia EDI:@EdiCustomerOrderDto?.CustomerOrderNumber
- Numer zamówienia Klienta:@EdiCustomerOrderDto?.CustomerPoNumber
- Numer klienta:@EdiCustomerOrderDto?.CustomerNumber
- Klient:@EdiCustomerOrderDto?.CustomerName
- Numer - odbiorcy:@(EdiCustomerOrderDto?.CustomerSequence?.ToString() ?? "N/A")
- Data - otrzymania:@(EdiCustomerOrderDto?.RecivedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Wysłano do - Syteline?:@((EdiCustomerOrderDto?.Posted?.ToString() ?? "0") == "0" ? "NIE" : "TAK")
- Data wysyłki do - Syteline:@(EdiCustomerOrderDto?.PostedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Data - zamówienia:@(EdiCustomerOrderDto?.OrderDate?.ToString("dd.MM.yyyy") ?? "N/A")
-
-
- Cena:@(EdiCustomerOrderDto?.Price?.ToString("F2") ?? "N/A")
- Waga:@(EdiCustomerOrderDto?.Weight?.ToString("F2") ?? "N/A")
- Magazyn:@EdiCustomerOrderDto?.Warehouse
- Gate:@EdiCustomerOrderDto?.Gate
- Kod odbiorcy:@EdiCustomerOrderDto?.RecipientCode
- Kod wysyłającego:@EdiCustomerOrderDto?.SenderCode
- Kod sprzedawcy:@EdiCustomerOrderDto?.SellerCode
- Kod kupującego:@EdiCustomerOrderDto?.BuyerCode
- Typ dokumentu:@EdiCustomerOrderDto?.DocType
-
-
+ + +
+
+ Numer zamówienia EDI: @EdiCustomerOrderDto?.CustomerOrderNumber
+ Numer zamówienia Klienta: @EdiCustomerOrderDto?.CustomerPoNumber
+ Numer klienta: @EdiCustomerOrderDto?.CustomerNumber
+ Klient: @EdiCustomerOrderDto?.CustomerName
+ Numer odbiorcy: @(EdiCustomerOrderDto?.CustomerSequence?.ToString() ?? "N/A")
+ Data otrzymania: @(EdiCustomerOrderDto?.RecivedDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Wysłano do Syteline?: @((EdiCustomerOrderDto?.Posted?.ToString() ?? "0") == "0" ? "NIE" : "TAK")
+ Data wysyłki do Syteline: @(EdiCustomerOrderDto?.PostedDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Data zamówienia: @(EdiCustomerOrderDto?.OrderDate?.ToString("dd.MM.yyyy") ?? "N/A")
+
+
+ Cena: @(EdiCustomerOrderDto?.Price?.ToString("F2") ?? "N/A")
+ Waga: @(EdiCustomerOrderDto?.Weight?.ToString("F2") ?? "N/A")
+ Magazyn: @EdiCustomerOrderDto?.Warehouse
+ Gate: @EdiCustomerOrderDto?.Gate
+ Kod odbiorcy: @EdiCustomerOrderDto?.RecipientCode
+ Kod wysyłającego: @EdiCustomerOrderDto?.SenderCode
+ Kod sprzedawcy: @EdiCustomerOrderDto?.SellerCode
+ Kod kupującego: @EdiCustomerOrderDto?.BuyerCode
+ Typ dokumentu: @EdiCustomerOrderDto?.DocType
+
+
+
+
+ +
Indeksy
+ + + + @{ + var order = context as EdiCustomerOrderLineDto; + + +
+
Szczegóły
+
+ Numer zamówienia EDI: @order?.CustomerOrderNumber
+ Linia: @order?.CustomerOrderLine
+ Pozycja: @order?.Item
+ Pozycja Klienta: @order?.CustomerItemNumber
+ Opis: @order?.Description
+ Łączna Ilość: @(order?.BlanketQty?.ToString("F2") ?? "N/A")
+ Status: @order?.TranslatedStatus
+
+
+ Cena: @(order?.ContPrice?.ToString("F2") ?? "N/A")
+ Ważne Od: @(order?.EffectiveDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ J/M: @order?.Uom
+ BoxType: @order?.BoxType
+ Address: @order?.Address
+ FinalDestination: @order?.FinalDestination
+ QtyPerBox: @(order?.QtyPerBox?.ToString() ?? "N/A") +
+
+
+
+ } +
+
+ + + + + + + + + + + + + + +
+ + @if (_isVisibleEdiCustomerOrderLine) + { +
Harmonogramy
+ + + + @{ + var detailLineItem = context as EdiCustomerOrderLineItemDto; + + +
+
Szczegóły
+
+ Numer Zamówienia: @detailLineItem?.CustomerOrderNumber
+ Linia: @detailLineItem?.CustomerOrderLine
+ Zwolnienie: @detailLineItem?.CustomerOrderRelease
+ Pozycja: @detailLineItem?.Item
+ Pozycja Klienta: @detailLineItem?.CustomerItem
+ Łączna Ilość Sztuk: @(detailLineItem?.QtyOrdered?.ToString("F2") ?? "N/A")
+ Cena: @(detailLineItem?.Price?.ToString("F2") ?? "N/A")
+ Data Wykonania: @(detailLineItem?.DueDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Data Rejestracji: @(detailLineItem?.ReleaseDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Magazyn: @detailLineItem?.Warehouse
+ Typ Dokumentu: @detailLineItem?.DocumentType
+
+
+ Kod VAT: @detailLineItem?.TaxCodeOne
+ J/M: @detailLineItem?.Uom
+ Numer Klienta: @detailLineItem?.CustomerOrderCustomerNumber
+ Opis: @detailLineItem?.Description
+ Status: @detailLineItem?.TranslatedStatus
+ RoutingCode: @detailLineItem?.RoutingCode
+ DeliveryCallNumber: @detailLineItem?.DeliveryCallNumber
+ UnloadingPoint: @detailLineItem?.UnloadingPoint
+ DestinationPoint: @detailLineItem?.DestinationPoint
+ PalletCode: @detailLineItem?.PalletCode
+ PalletNumber: @detailLineItem?.PalletNumber +
+
+
+
+ } +
+
+ + + + + + + + + + + + +
+ }
+ + FA Krosno Manager © @(DateTime.Now.Year) +
-
-
Indeksy
- - - - @{ - var order = context as EdiCustomerOrderLineDto; - - -
-
Szczegóły
-
- Numer zamówienia EDI:@order?.CustomerOrderNumber
- Linia:@order?.CustomerOrderLine
- Pozycja:@order?.Item
- Pozycja Klienta:@order?.CustomerItemNumber
- Opis:@order?.Description
- Łączna Ilość:@(order?.BlanketQty?.ToString("F2") ?? "N/A")
- Status:@order?.TranslatedStatus
-
-
- Cena:@(order?.ContPrice?.ToString("F2") ?? "N/A")
- Ważne - Od:@(order?.EffectiveDate?.ToString("dd.MM.yyyy") ?? "N/A")
- J/M:@order?.Uom
- BoxType:@order?.BoxType
- Address:@order?.Address
- FinalDestination:@order?.FinalDestination
- QtyPerBox:@(order?.QtyPerBox?.ToString() ?? "N/A") -
-
-
-
- } -
-
- - - - - - - - - - - - - - -
- @if (_isVisibleEdiCustomerOrderLine) - { -
-
Harmonogramy
- - - - @{ - var detailLineItem = context as EdiCustomerOrderLineItemDto; - - -
-
Szczegóły
-
- Numer Zamówienia:@detailLineItem?.CustomerOrderNumber
- Linia:@detailLineItem?.CustomerOrderLine
- Zwolnienie:@detailLineItem?.CustomerOrderRelease
- Pozycja:@detailLineItem?.Item
- Pozycja Klienta:@detailLineItem?.CustomerItem
- Łączna Ilość - Sztuk:@(detailLineItem?.QtyOrdered?.ToString("F2") ?? "N/A")
- Cena:@(detailLineItem?.Price?.ToString("F2") ?? "N/A")
- Data - Wykonania:@(detailLineItem?.DueDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Data - Rejestracji:@(detailLineItem?.ReleaseDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Magazyn:@detailLineItem?.Warehouse
- Typ Documentu:@detailLineItem?.DocumentType
-
-
- Kod VAT:@detailLineItem?.TaxCodeOne
- J/M:@detailLineItem?.Uom
- Numer - Klienta:@detailLineItem?.CustomerOrderCustomerNumber
- Opis:@detailLineItem?.Description
- Status:@detailLineItem?.TranslatedStatus
- RoutingCode:@detailLineItem?.RoutingCode
- DeliveryCallNumber:@detailLineItem?.DeliveryCallNumber
- UnloadingPoint:@detailLineItem?.UnloadingPoint
- DestinationPoint:@detailLineItem?.DestinationPoint
- PalletCode:@detailLineItem?.PalletCode
- PalletNumber:@detailLineItem?.PalletNumber -
-
-
-
- } -
-
- - - - - - - - - - - - -
- }
@code { @@ -202,13 +192,25 @@ SfGrid? _ediCustomerOrderLineItemsGrid; private bool _isVisibleEdiCustomerOrderLine; - - protected override async Task OnInitializedAsync() + + protected override async Task OnAfterRenderAsync(bool firstRender) { - EdiCustomerOrderDto? ediCustomerOrder = await EdiCustomerOrderService.GetEdiCustomerOrderAsync(CustomerOrderId); + if (firstRender) + { + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - EdiCustomerOrderDto = ediCustomerOrder; - _ediCustomerOrderLines = ediCustomerOrder?.EdiCustomerOrderLines.ToList() ?? []; + if (currentUser.Identity?.IsAuthenticated == false) + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + EdiCustomerOrderDto? ediCustomerOrder = await EdiCustomerOrderService.GetEdiCustomerOrderAsync(CustomerOrderId); + + EdiCustomerOrderDto = ediCustomerOrder; + _ediCustomerOrderLines = ediCustomerOrder?.EdiCustomerOrderLines.ToList() ?? []; + } + } } private void OnSelectedLineRow(RowSelectEventArgs obj) diff --git a/OrdersManagement/Components/Pages/EdiCustomerOrders.razor b/OrdersManagement/Components/Pages/EdiCustomerOrders.razor index 42eb571..2f50c8a 100644 --- a/OrdersManagement/Components/Pages/EdiCustomerOrders.razor +++ b/OrdersManagement/Components/Pages/EdiCustomerOrders.razor @@ -1,9 +1,11 @@ @page "/EdiCustomerOrders" -@rendermode InteractiveServer +@attribute [Authorize] @inject EdiCustomerOrderService EdiCustomerOrderService @inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider +@using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using OrdersManagement.Models @using SytelineSaAppEfDataModel.Dtos @@ -14,120 +16,115 @@ @using SelectionType = Syncfusion.Blazor.Grids.SelectionType @inherits LayoutComponentBase -
-
Zamówienia Klienta EDI
-
-
- - -
-
-
- @if (_isVisible) - { -
-
- @_text +
+ + +

Zamówienia Klienta EDI

+
+ +
+
+ + +
-
-
- } - - - - @{ - var order = context as EdiCustomerOrderDto; - - -
-
- Numer zamówienia EDI:@order?.CustomerOrderNumber
- Numer zamówienia Klienta:@order?.CustomerPoNumber
- Numer klienta:@order?.CustomerNumber
- Klient:@order?.CustomerName
- Numer - odbiorcy:@(order?.CustomerSequence?.ToString() ?? "N/A")
- Data - otrzymania:@(order?.RecivedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Wysłano do - Syteline?:@((order?.Posted?.ToString() ?? "0") == "0" ? "NIE" : "TAK")
- Data wysyłki do - Syteline:@(order?.PostedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Data - zamówienia:@(order?.OrderDate?.ToString("dd.MM.yyyy") ?? "N/A")
-
-
- Cena:@(order?.Price?.ToString("F2") ?? "N/A")
- Waga:@(order?.Weight?.ToString("F2") ?? "N/A")
- Magazyn:@order?.Warehouse
- Gate:@order?.Gate
- Kod odbiorcy:@order?.RecipientCode
- Kod wysyłającego:@order?.SenderCode
- Kod sprzedawcy:@order?.SellerCode
- Kod kupującego:@order?.BuyerCode
- Typ dokumentu:@order?.DocType
-
-
-
-
- } -
-
- - - - - - - - - - - - - -
- - - - @if (_responses.Any(x => x.Status == 1)) - { - foreach (ResponseModel? response in _responses.Where(x => x.Status == 1)) - { -

Zamówienie EDI @response.Identifier zostało poprawnie zaksięgowane w Zamówieniach klienta pod - numerem '@response.ExternalIdentifier'

- } - } - @if (_responses.Any(x => x.Status == 0)) - { - foreach (ResponseModel? response in _responses.Where(x => x.Status == 0)) - { -

Błąd: Zamówienie EDI @response.Identifier nie zostało poprawnie zaksięgowane w Zamówieniach - klienta.
Lista błędów:
@response.Message

- } - } -
-
- - - -
+ @if (_isVisible) + { +
+
+ @_text +
+
+ } + + + + + @{ + var order = context as EdiCustomerOrderDto; + + +
+
+ Numer zamówienia EDI: @order?.CustomerOrderNumber
+ Numer zamówienia Klienta: @order?.CustomerPoNumber
+ Numer klienta: @order?.CustomerNumber
+ Klient: @order?.CustomerName
+ Numer odbiorcy: @(order?.CustomerSequence?.ToString() ?? "N/A")
+ Data otrzymania: @(order?.RecivedDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Wysłano do Syteline?: @((order?.Posted?.ToString() ?? "0") == "0" ? "NIE" : "TAK")
+ Data wysyłki do Syteline: @(order?.PostedDate?.ToString("dd.MM.yyyy") ?? "N/A")
+ Data zamówienia: @(order?.OrderDate?.ToString("dd.MM.yyyy") ?? "N/A")
+
+
+ Cena: @(order?.Price?.ToString("F2") ?? "N/A")
+ Waga: @(order?.Weight?.ToString("F2") ?? "N/A")
+ Magazyn: @order?.Warehouse
+ Gate: @order?.Gate
+ Kod odbiorcy: @order?.RecipientCode
+ Kod wysyłającego: @order?.SenderCode
+ Kod sprzedawcy: @order?.SellerCode
+ Kod kupującego: @order?.BuyerCode
+ Typ dokumentu: @order?.DocType
+
+
+
+
+ } +
+
+ + + + + + + + + + + + + +
+ + + + + @if (_responses.Any(x => x.Status == 1)) + { + foreach (ResponseModel? response in _responses.Where(x => x.Status == 1)) + { +

Zamówienie EDI @response.Identifier zostało poprawnie zaksięgowane w Zamówieniach klienta pod numerem '@response.ExternalIdentifier'

+ } + } + @if (_responses.Any(x => x.Status == 0)) + { + foreach (ResponseModel? response in _responses.Where(x => x.Status == 0)) + { +

Błąd: Zamówienie EDI @response.Identifier nie zostało poprawnie zaksięgowane w Zamówieniach klienta.
Lista błędów:
@response.Message

+ } + } +
+
+ + + +
+ + + FA Krosno Manager © @(DateTime.Now.Year) + +
@code { @@ -145,9 +142,21 @@ private string _text = "Księguj bieżący"; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { - await LoadData(); + if (firstRender) + { + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false) + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + await LoadData(); + } + } } private void OnRowDoubleClick(RecordDoubleClickEventArgs obj) diff --git a/OrdersManagement/Components/Pages/Admin/Users/LoginModule.razor b/OrdersManagement/Components/Pages/Login.razor similarity index 67% rename from OrdersManagement/Components/Pages/Admin/Users/LoginModule.razor rename to OrdersManagement/Components/Pages/Login.razor index c40d28c..b852641 100644 --- a/OrdersManagement/Components/Pages/Admin/Users/LoginModule.razor +++ b/OrdersManagement/Components/Pages/Login.razor @@ -1,47 +1,43 @@ @page "/login" -@rendermode InteractiveServer @attribute [AllowAnonymous] @using Microsoft.AspNetCore.Authorization -@using Microsoft.AspNetCore.Components.Authorization @using OrdersManagement.Models @using Syncfusion.Blazor.Inputs @using Syncfusion.Blazor.Buttons @using Syncfusion.Blazor.Cards @inject UserService UserService @inject NavigationManager NavigationManager -@inject AuthenticationStateProvider AuthenticationStateProvider -
-
Logowanie
- - @if (!string.IsNullOrEmpty(TempPassword)) - { -
- Twoje tymczasowe hasło to: @TempPassword. Użyj go do pierwszego logowania. -
- } - - - +
+ + +

Logowanie

+
+ @if (!string.IsNullOrEmpty(TempPassword)) + { +
+ Twoje tymczasowe hasło to: @TempPassword. Użyj go do pierwszego logowania. +
+ } + - + -
- - - +
+ + +
-
- +
+ - +
@@ -56,37 +52,36 @@ @if (ShowChangePassword) { -
-
Zmień hasło
- +
+
Zmień hasło
+ - + -
- - - +
+ + +
-
- - - +
+ + +
- Zmień hasło + Zmień hasło
} + + Orders Management System © @(DateTime.Now.Year) + -
@code { diff --git a/OrdersManagement/Components/Pages/Main.razor b/OrdersManagement/Components/Pages/Main.razor new file mode 100644 index 0000000..44ae64f --- /dev/null +++ b/OrdersManagement/Components/Pages/Main.razor @@ -0,0 +1,20 @@ +@page "/" +@using Microsoft.AspNetCore.Authorization + +@attribute [AllowAnonymous] + +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider +@inject NavigationManager NavigationManager + +@code { + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await CustomAuthenticationStateProvider.MarkUserAsLoggedOut(); + NavigationManager.NavigateTo("/login"); + } + } + +} \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/RedirectToLogin.razor b/OrdersManagement/Components/Pages/RedirectToLogin.razor deleted file mode 100644 index d8f1d13..0000000 --- a/OrdersManagement/Components/Pages/RedirectToLogin.razor +++ /dev/null @@ -1,8 +0,0 @@ -@inject NavigationManager Navigation - -@code { - protected override void OnInitialized() - { - Navigation.NavigateTo("/login"); - } -} \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/Admin/Users/RegistrationModule.razor b/OrdersManagement/Components/Pages/Register.razor similarity index 100% rename from OrdersManagement/Components/Pages/Admin/Users/RegistrationModule.razor rename to OrdersManagement/Components/Pages/Register.razor diff --git a/OrdersManagement/Components/Pages/ScheduleOrder.razor b/OrdersManagement/Components/Pages/ScheduleOrder.razor index 91a9827..943336a 100644 --- a/OrdersManagement/Components/Pages/ScheduleOrder.razor +++ b/OrdersManagement/Components/Pages/ScheduleOrder.razor @@ -1,154 +1,159 @@ @page "/ScheduleOrder/{ScheduleOrderId:int}" @attribute [Authorize] +@using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.Lists +@using Syncfusion.Blazor.Cards @inject ScheduleOrderService ScheduleOrderService +@inject NavigationManager NavigationManager +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider -
-
Zamówienie DELFOR nr @ScheduleOrderDto?.PONum
- - - - - - -
-
Indeksy
- - - - @{ - IList? scheduleOrderDetailMiscs = (@context as ScheduleOrderDetailDto)?.ScheduleOrderDetailMiscs; - IList? scheduleOrderDetailDetails = (@context as ScheduleOrderDetailDto)?.ScheduleOrderDetailDetails; +
+ + +

Zamówienie DELFOR nr @(ScheduleOrderDto?.PONum ?? "Brak numeru")

+
+ + + + + + + - - - - - - -
-
Harmonogramy
- - - - - @{ - IList? scheduleOrderDetailDetailMiscs = (@detailDetail as ScheduleOrderDetailDetailDto)?.ScheduleOrderDetailDetailMiscs; +
Indeksy
+ + + + @{ + IList? scheduleOrderDetailMiscs = (@context as ScheduleOrderDetailDto)?.ScheduleOrderDetailMiscs; + IList? scheduleOrderDetailDetails = (@context as ScheduleOrderDetailDto)?.ScheduleOrderDetailDetails; - - - - - - - } - - - - - - - - - - - - - - } -
-
- - - - - - - - - - - -
+ + + + + + + +
Harmonogramy
+ + + + + @{ + IList? scheduleOrderDetailDetailMiscs = (@detailDetail as ScheduleOrderDetailDetailDto)?.ScheduleOrderDetailDetailMiscs; + + + + + + + + } + + + + + + + + + + + + + + } + + + + + + + + + + + + + + +
+ + FA Krosno Manager © @(DateTime.Now.Year) + +
+ @code { [Parameter] public int ScheduleOrderId { get; set; } private IEnumerable? _scheduleOrderDetails; private ScheduleOrderDto? ScheduleOrderDto { get; set; } - - protected override async Task OnInitializedAsync() + + protected override async Task OnAfterRenderAsync(bool firstRender) { - ScheduleOrderDto = await ScheduleOrderService.GetScheduleOrderAsync(ScheduleOrderId); - - _scheduleOrderDetails = ScheduleOrderDto?.ScheduleOrderDetails; - - if (ScheduleOrderDto is not null && _scheduleOrderDetails is not null) + if (firstRender) { - foreach (ScheduleOrderDetailDto scheduleOrderDetailDto in _scheduleOrderDetails) + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false) { - scheduleOrderDetailDto.OrderNumber = ScheduleOrderDto?.PONum; - scheduleOrderDetailDto.RecipientCode = ScheduleOrderDto?.RecipientCode; - scheduleOrderDetailDto.RecipientName = ScheduleOrderDto?.RecipientName; - scheduleOrderDetailDto.PurchaserName = ScheduleOrderDto?.PurchaserCode; + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + ScheduleOrderDto = await ScheduleOrderService.GetScheduleOrderAsync(ScheduleOrderId); + + _scheduleOrderDetails = ScheduleOrderDto?.ScheduleOrderDetails; + + if (ScheduleOrderDto is not null && _scheduleOrderDetails is not null) + { + foreach (ScheduleOrderDetailDto scheduleOrderDetailDto in _scheduleOrderDetails) + { + scheduleOrderDetailDto.OrderNumber = ScheduleOrderDto?.PONum; + scheduleOrderDetailDto.RecipientCode = ScheduleOrderDto?.RecipientCode; + scheduleOrderDetailDto.RecipientName = ScheduleOrderDto?.RecipientName; + scheduleOrderDetailDto.PurchaserName = ScheduleOrderDto?.PurchaserCode; + } + } + + StateHasChanged(); } } - - StateHasChanged(); } private void OnRowDataBound(RowDataBoundEventArgs args) diff --git a/OrdersManagement/Components/Pages/ScheduleOrders.razor b/OrdersManagement/Components/Pages/ScheduleOrders.razor index bd03173..551dfc0 100644 --- a/OrdersManagement/Components/Pages/ScheduleOrders.razor +++ b/OrdersManagement/Components/Pages/ScheduleOrders.razor @@ -2,16 +2,16 @@ @attribute [Authorize] +@using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using OrdersManagement.Components.Pages.Shared @using Syncfusion.Blazor.Grids @inject ScheduleOrderService ScheduleOrderService +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider +@inject NavigationManager NavigationManager; -
-
Zamówienia DELFOR
- -
+ @code { private IEnumerable _scheduleOrders = []; @@ -20,8 +20,17 @@ { if (firstRender) { - _scheduleOrders = await FetchScheduleOrdersAsync(); - StateHasChanged(); + ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + + if (currentUser.Identity?.IsAuthenticated == false) + { + NavigationManager.NavigateTo("/Unauthorized"); + } + else + { + _scheduleOrders = await FetchScheduleOrdersAsync(); + StateHasChanged(); + } } } diff --git a/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor b/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor index 2a9509e..1523abe 100644 --- a/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor +++ b/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor @@ -1,116 +1,103 @@ @inject NavigationManager NavigationManager @using Syncfusion.Blazor.Grids +@using Syncfusion.Blazor.Cards @inherits LayoutComponentBase @inject ScheduleOrderService ScheduleOrderService -
- - - - - - - - - - - - @{ - IList? scheduleOrderDetails = (@context as ScheduleOrderDto)?.ScheduleOrderDetails; - - - - - - - - - - - - @{ - IList? scheduleOrderDetailsDetails = (@detail as ScheduleOrderDetailDto)?.ScheduleOrderDetailDetails; - - - - - - - - - - - - - - } - - - - - - - - } - - - - - - +
+ + +

Zamówienia DELFOR

+
+ + + + + + + + + + + + + @{ + IList? scheduleOrderDetails = (@context as ScheduleOrderDto)?.ScheduleOrderDetails; + + + + + + + + + + + + @{ + IList? scheduleOrderDetailsDetails = (@detail as ScheduleOrderDetailDto)?.ScheduleOrderDetailDetails; + + + + + + + + + + + + + + } + + + + + + + + } + + + + + + + + + Orders Management System © @(DateTime.Now.Year) + +
@code { diff --git a/OrdersManagement/Components/Pages/Unauthorized.razor b/OrdersManagement/Components/Pages/Unauthorized.razor new file mode 100644 index 0000000..78bdb97 --- /dev/null +++ b/OrdersManagement/Components/Pages/Unauthorized.razor @@ -0,0 +1,35 @@ +@page "/Unauthorized" +@using Microsoft.AspNetCore.Authorization + +@attribute [AllowAnonymous] + +@using Syncfusion.Blazor.Cards +@using Syncfusion.Blazor.Buttons + +@inject NavigationManager NavigationManager + +
+ + +

Brak autoryzacji

+
+ +

+ Ups! Wygląda na to, że nie masz dostępu do tej strony. Aby kontynuować, zaloguj się do swojego konta. +

+ + Przejdź do logowania + +
+ + Orders Management System © @(DateTime.Now.Year) + +
+
+ +@code { + private void NavigateToLogin() + { + NavigationManager.NavigateTo("/login"); + } +} \ No newline at end of file diff --git a/OrdersManagement/CustomAuthenticationStateProvider.cs b/OrdersManagement/CustomAuthenticationStateProvider.cs index 98cbae0..de6b2f6 100644 --- a/OrdersManagement/CustomAuthenticationStateProvider.cs +++ b/OrdersManagement/CustomAuthenticationStateProvider.cs @@ -10,18 +10,20 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage private string? _token; private ClaimsPrincipal _currentUser = new(new ClaimsIdentity()); - public override Task GetAuthenticationStateAsync() + public override async Task GetAuthenticationStateAsync() { + _token = await localStorage.GetItemAsync("authToken"); + if (string.IsNullOrEmpty(_token)) { - return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()))); + return await Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()))); } var handler = new JwtSecurityTokenHandler(); var jwtToken = handler.ReadJwtToken(_token); - var identity = new ClaimsIdentity(jwtToken.Claims, "jwt"); + var identity = new ClaimsIdentity(jwtToken.Claims, "jwt", JwtRegisteredClaimNames.Sub, null); _currentUser = new ClaimsPrincipal(identity); - return Task.FromResult(new AuthenticationState(_currentUser)); + return await Task.FromResult(new AuthenticationState(_currentUser)); } public async Task MarkUserAsAuthenticated(string? token) @@ -30,7 +32,7 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage await localStorage.SetItemAsync("authToken", token); var handler = new JwtSecurityTokenHandler(); var jwtToken = handler.ReadJwtToken(token); - var identity = new ClaimsIdentity(jwtToken.Claims, "jwt"); + var identity = new ClaimsIdentity(jwtToken.Claims, "jwt", JwtRegisteredClaimNames.Sub, null); _currentUser = new ClaimsPrincipal(identity); NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser))); } @@ -42,21 +44,8 @@ public class CustomAuthenticationStateProvider(ILocalStorageService localStorage _currentUser = new ClaimsPrincipal(new ClaimsIdentity()); NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser))); } - - public async Task InitializeAsync() - { - _token = await localStorage.GetItemAsync("authToken"); - - if (!string.IsNullOrEmpty(_token)) - { - var handler = new JwtSecurityTokenHandler(); - var jwtToken = handler.ReadJwtToken(_token); - var identity = new ClaimsIdentity(jwtToken.Claims, "jwt"); - _currentUser = new ClaimsPrincipal(identity); - NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(_currentUser))); - } - } public string? GetToken() => _token; + public ClaimsPrincipal GetCurrentUser() => _currentUser; } diff --git a/OrdersManagement/Program.cs b/OrdersManagement/Program.cs index 71ece89..53ded2d 100644 --- a/OrdersManagement/Program.cs +++ b/OrdersManagement/Program.cs @@ -33,7 +33,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) }); builder.Services.AddAuthorizationCore(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHttpClient("FaKrosnoApi", client => { diff --git a/OrdersManagement/Services/CustomerOrderService.cs b/OrdersManagement/Services/CustomerOrderService.cs index 2adf0d2..82fd204 100644 --- a/OrdersManagement/Services/CustomerOrderService.cs +++ b/OrdersManagement/Services/CustomerOrderService.cs @@ -5,7 +5,7 @@ namespace OrdersManagement.Services; public class CustomerOrderService( IHttpClientFactory httpClientFactory, - AuthenticationStateProvider authenticationStateProvider) + CustomAuthenticationStateProvider authenticationStateProvider) : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetCustomerOrdersAsync() @@ -25,7 +25,7 @@ public class CustomerOrderService( { try { - return await GetByIdAsync($"api/CustomerOrders/by-order-number/?customerOrderNumber={customerOrderNumber}"); + return await GetEntityAsync($"api/CustomerOrders/by-order-number/?customerOrderNumber={customerOrderNumber}"); } catch (HttpRequestException ex) { diff --git a/OrdersManagement/Services/EdiCustomerOrderService.cs b/OrdersManagement/Services/EdiCustomerOrderService.cs index 01c9507..aea72ca 100644 --- a/OrdersManagement/Services/EdiCustomerOrderService.cs +++ b/OrdersManagement/Services/EdiCustomerOrderService.cs @@ -4,7 +4,7 @@ using SytelineSaAppEfDataModel.Dtos; namespace OrdersManagement.Services { - public class EdiCustomerOrderService(IHttpClientFactory httpClientFactory, AuthenticationStateProvider authenticationStateProvider, ErrorLogService errorLogService) : ServiceBase(httpClientFactory, authenticationStateProvider) + public class EdiCustomerOrderService(IHttpClientFactory httpClientFactory, CustomAuthenticationStateProvider authenticationStateProvider, ErrorLogService errorLogService) : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetEdiCustomerOrdersAsync() { @@ -23,7 +23,7 @@ namespace OrdersManagement.Services { try { - return await GetByIdAsync($"api/EdiCustomerOrders/by-order-number/?customerOrderNumber={customerOrderNumber}"); + return await GetEntityAsync($"api/EdiCustomerOrders/by-order-number/?customerOrderNumber={customerOrderNumber}"); } catch (HttpRequestException ex) { diff --git a/OrdersManagement/Services/ErrorLogService.cs b/OrdersManagement/Services/ErrorLogService.cs index fe1823e..f169790 100644 --- a/OrdersManagement/Services/ErrorLogService.cs +++ b/OrdersManagement/Services/ErrorLogService.cs @@ -5,7 +5,7 @@ namespace OrdersManagement.Services; public class ErrorLogService( IHttpClientFactory httpClientFactory, - AuthenticationStateProvider authenticationStateProvider) + CustomAuthenticationStateProvider authenticationStateProvider) : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetErrorLogsAsync(Guid customerOrderNumber) diff --git a/OrdersManagement/Services/HangfireService.cs b/OrdersManagement/Services/HangfireService.cs index bdc7f28..86701c1 100644 --- a/OrdersManagement/Services/HangfireService.cs +++ b/OrdersManagement/Services/HangfireService.cs @@ -2,27 +2,30 @@ using OrdersManagementDataModel.Dtos; namespace OrdersManagement.Services; -public class HangfireService(HttpClient httpClient) +public class HangfireService( + IHttpClientFactory httpClientFactory, + CustomAuthenticationStateProvider authenticationStateProvider) + : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetTaskSchedulersAsync() { - return await httpClient.GetFromJsonAsync>("api/HangfireJobs/GetTasks"); + return await GetListAsync("api/HangfireJobs/"); } public async Task GetTaskSchedulerAsync(Guid id) { - return await httpClient.GetFromJsonAsync($"api/HangfireJobs/{id}"); + return await GetEntityAsync($"api/HangfireJobs/{id}"); } public async Task AddTaskSchedulerAsync(TaskSchedulerDto taskSchedulerDto) { - HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync("api/HangfireJobs/AddTask", taskSchedulerDto); + HttpResponseMessage responseMessage = await PostAsJsonAsync("api/HangfireJobs/add", taskSchedulerDto); return responseMessage.IsSuccessStatusCode ? 1 : 0; } public async Task DeleteTaskSchedulerAsync(TaskSchedulerDto taskSchedulerDto) { - HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync("api/HangfireJobs/DeleteTask", taskSchedulerDto); + HttpResponseMessage responseMessage = await PostAsJsonAsync("api/HangfireJobs/delete", taskSchedulerDto); return responseMessage.IsSuccessStatusCode ? 1 : 0; } } \ No newline at end of file diff --git a/OrdersManagement/Services/RoleService.cs b/OrdersManagement/Services/RoleService.cs index 3c6f11a..60f070d 100644 --- a/OrdersManagement/Services/RoleService.cs +++ b/OrdersManagement/Services/RoleService.cs @@ -2,40 +2,38 @@ using OrdersManagementDataModel.Dtos; namespace OrdersManagement.Services; -public class RoleService(HttpClient httpClient) +public class RoleService( + IHttpClientFactory httpClientFactory, + CustomAuthenticationStateProvider authenticationStateProvider) + : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetRolesAsync() { - return await httpClient.GetFromJsonAsync>("api/Roles"); + return await GetListAsync("api/Roles"); } public async Task GetRoleAsync(Guid roleId) { - return await httpClient.GetFromJsonAsync($"api/Roles/by-id/?id={roleId}"); + return await GetEntityAsync($"api/Roles/by-id/?id={roleId}"); } public async Task GetRoleByNameAsync(string roleName) { - return await httpClient.GetFromJsonAsync($"api/Roles/by-name/?name={roleName}"); + return await GetEntityAsync($"api/Roles/by-name/?name={roleName}"); } - public async Task AddRoleAsync(RoleDto role) + public async Task AddRoleAsync(RoleDto role) { - await httpClient.PostAsJsonAsync("api/Roles", role); + return await PostAsJsonAsync("api/Roles", role); } - public async Task UpdateRoleAsync(RoleDto role) + public async Task UpdateRoleAsync(RoleDto role) { - await httpClient.PutAsJsonAsync("api/Roles", role); + return await PutAsJsonAsync("api/Roles", role); } - public async Task DeleteRoleAsync(Guid roleId) + public async Task DeleteRoleAsync(Guid roleId) { - await httpClient.DeleteAsync($"api/Roles/?id={roleId}"); + return await DeleteAsync($"api/Roles/?id={roleId}"); } - - // public async Task?> GetUsersInRoleAsync(Guid roleId) - // { - // return await httpClient.GetFromJsonAsync>($"api/Roles/{roleId}/Users"); - // } } \ No newline at end of file diff --git a/OrdersManagement/Services/ScheduleOrderService.cs b/OrdersManagement/Services/ScheduleOrderService.cs index 7fc47d4..41e23db 100644 --- a/OrdersManagement/Services/ScheduleOrderService.cs +++ b/OrdersManagement/Services/ScheduleOrderService.cs @@ -7,7 +7,7 @@ namespace OrdersManagement.Services; public class ScheduleOrderService( IHttpClientFactory httpClientFactory, - AuthenticationStateProvider authenticationStateProvider) + CustomAuthenticationStateProvider authenticationStateProvider) : ServiceBase(httpClientFactory, authenticationStateProvider) { public async Task?> GetScheduleOrdersAsync() @@ -27,7 +27,7 @@ public class ScheduleOrderService( { try { - return await GetByIdAsync($"api/ScheduleOrders/{scheduleOrderId}"); + return await GetEntityAsync($"api/ScheduleOrders/{scheduleOrderId}"); } catch (HttpRequestException ex) { diff --git a/OrdersManagement/Services/ServiceBase.cs b/OrdersManagement/Services/ServiceBase.cs index be71ff5..1d83dec 100644 --- a/OrdersManagement/Services/ServiceBase.cs +++ b/OrdersManagement/Services/ServiceBase.cs @@ -4,26 +4,28 @@ namespace OrdersManagement.Services; public class ServiceBase where T : class { - private readonly AuthenticationStateProvider _authenticationStateProvider; + private readonly CustomAuthenticationStateProvider _authenticationStateProvider; private readonly HttpClient _httpClient; - protected ServiceBase(IHttpClientFactory httpClientFactory, AuthenticationStateProvider authenticationStateProvider) + protected ServiceBase(IHttpClientFactory httpClientFactory, CustomAuthenticationStateProvider authenticationStateProvider) { _authenticationStateProvider = authenticationStateProvider; _httpClient = httpClientFactory.CreateClient("FaKrosnoApi"); - - _ = Configure(); } protected async Task?> GetListAsync(string request) { + Configure(); + var response = await _httpClient.GetAsync(request); response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync>(); } - protected async Task GetByIdAsync(string request) + protected async Task GetEntityAsync(string request) { + Configure(); + var response = await _httpClient.GetAsync(request); response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync(); @@ -31,22 +33,54 @@ public class ServiceBase where T : class protected async Task PostAsync(string request) { + Configure(); + var response = await _httpClient.PostAsync(request, null); response.EnsureSuccessStatusCode(); return response; } - - private async Task Configure() + + protected async Task PostAsJsonAsync(string request, T obj) { - var token = await GetToken(); + Configure(); + + var response = await _httpClient.PostAsJsonAsync(request, obj); + response.EnsureSuccessStatusCode(); + return response; + } + + protected async Task PostAsJsonAsync(string request, object obj) + { + Configure(); + + var response = await _httpClient.PostAsJsonAsync(request, obj); + response.EnsureSuccessStatusCode(); + return response; + } + + protected async Task PutAsJsonAsync(string request, T obj) + { + Configure(); + + var response = await _httpClient.PutAsJsonAsync(request, obj); + response.EnsureSuccessStatusCode(); + return response; + } + + protected async Task DeleteAsync(string request) + { + Configure(); + + var response = await _httpClient.DeleteAsync(request); + response.EnsureSuccessStatusCode(); + return response; + } + + private void Configure() + { + var token = _authenticationStateProvider.GetToken(); _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); } - - private async Task GetToken() - { - await ((CustomAuthenticationStateProvider)_authenticationStateProvider).InitializeAsync(); - return ((CustomAuthenticationStateProvider)_authenticationStateProvider).GetToken(); - } } \ No newline at end of file diff --git a/OrdersManagement/Services/UserService.cs b/OrdersManagement/Services/UserService.cs index 07b7c67..a48c321 100644 --- a/OrdersManagement/Services/UserService.cs +++ b/OrdersManagement/Services/UserService.cs @@ -1,30 +1,31 @@ -using Blazored.LocalStorage; -using Microsoft.AspNetCore.Components.Authorization; using OrdersManagement.Models; using OrdersManagementDataModel.Dtos; namespace OrdersManagement.Services; -public class UserService(IHttpClientFactory clientFactory, AuthenticationStateProvider authStateProvider) +public class UserService( + IHttpClientFactory httpClientFactory, + CustomAuthenticationStateProvider authenticationStateProvider) + : ServiceBase(httpClientFactory, authenticationStateProvider) { - private readonly HttpClient _httpClient = clientFactory.CreateClient("FaKrosnoApi"); + private readonly HttpClient _httpClient = httpClientFactory.CreateClient("FaKrosnoApi"); public async Task?> GetUsersAsync() { - return await _httpClient.GetFromJsonAsync>("api/Users"); + return await GetListAsync("api/Users"); } public async Task AuthenticateUserAsync(string login, string password) { try { - var response = await _httpClient.PostAsJsonAsync("api/Users/login", new { Login = login, Password = password }); + var response = await PostAsJsonAsync("api/Users/login", new { Login = login, Password = password }); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadFromJsonAsync(); if (result?.Token == null) return null; - await ((CustomAuthenticationStateProvider)authStateProvider).MarkUserAsAuthenticated(result.Token); + await authenticationStateProvider.MarkUserAsAuthenticated(result.Token); return await GetUserByUsernameAsync(login); } @@ -37,26 +38,26 @@ public class UserService(IHttpClientFactory clientFactory, AuthenticationStatePr public async Task GetUserAsync(Guid userId) { - return await _httpClient.GetFromJsonAsync($"api/Users/by-id/?id={userId}"); + return await GetEntityAsync($"api/Users/by-id/?id={userId}"); } public async Task GetUserByUsernameAsync(string username) { - return await _httpClient.GetFromJsonAsync($"api/Users/by-username/?username={username}"); + return await GetEntityAsync($"api/Users/by-username/?username={username}"); } public async Task AddUserAsync(UserDto user) { - return await _httpClient.PostAsJsonAsync("api/Users", user); + return await PostAsJsonAsync("api/Users", user); } - public async Task UpdateUserAsync(UserDto user) + public async Task UpdateUserAsync(UserDto user) { - await _httpClient.PutAsJsonAsync("api/Users", user); + return await PutAsJsonAsync("api/Users", user); } - public async Task DeleteUserAsync(Guid userId) + public async Task DeleteUserAsync(Guid userId) { - await _httpClient.DeleteAsync($"api/Users/?id={userId}"); + return await DeleteAsync($"api/Users/?id={userId}"); } } \ No newline at end of file diff --git a/OrdersManagement/wwwroot/material.css b/OrdersManagement/wwwroot/material.css index de11d21..7faad03 100644 --- a/OrdersManagement/wwwroot/material.css +++ b/OrdersManagement/wwwroot/material.css @@ -63429,3 +63429,89 @@ html, body { .e-grid .e-row.highlight-red .e-rowcell { background-color: #ffcccc !important; } + +.e-menu-container { + background-color: #bad9ff; /* Tło głównego menu */ + border: none; /* Usunięcie domyślnego obramowania */ + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Czcionka spójna z projektem */ +} + +/* Stylizacja elementów menu na poziomie głównym */ +.e-menu-container .e-menu .e-menu-item { + color: #1a3c66; /* Ciemniejszy niebieski dla kontrastu */ + font-size: 14px; /* Rozmiar czcionki */ + padding: 8px 16px; /* Wewnętrzne odstępy */ + transition: background-color 0.3s ease; /* Płynne przejścia */ +} + +/* Stylizacja przy najechaniu (hover) */ +.e-menu-container .e-menu .e-menu-item:hover { + background-color: #b3d9ff; /* Jasniejsze tło przy najechaniu */ +} + +/* Stylizacja przy fokusie */ +.e-menu-container .e-menu .e-menu-item.e-focused { + background-color: #b3d9ff; /* Tło przy fokusie */ + color: #1a3c66; /* Kolor tekstu */ +} + +/* Stylizacja wybranego elementu */ +.e-menu-container .e-menu .e-menu-item.e-selected { + background-color: #8ec6fe; /* Tło wybranego elementu */ + color: #1a3c66; /* Kolor tekstu */ + font-weight: 600; /* Pogrubienie dla wybranego */ +} + +/* Stylizacja ikon w menu */ +.e-menu-container .e-menu .e-menu-item .e-menu-icon { + margin-right: 8px; /* Odstęp między ikoną a tekstem */ + color: #1a3c66; /* Kolor ikon */ +} + +/* Stylizacja podmenu (poziom zagnieżdżony) */ +.e-menu-container .e-menu .e-menu-item .e-ul { + background-color: #bad9ff; /* Tło podmenu */ + border: 1px solid #8ec6fe; /* Delikatne obramowanie podmenu */ + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Cień dla efektu unoszenia */ +} + +/* Elementy w podmenu */ +.e-menu-container .e-menu .e-menu-item .e-ul .e-menu-item { + color: #1a3c66; /* Kolor tekstu w podmenu */ + padding: 6px 14px; /* Mniejsze odstępy w podmenu */ +} + +/* Hover w podmenu */ +.e-menu-container .e-menu .e-menu-item .e-ul .e-menu-item:hover { + background-color: #b3d9ff; /* Tło przy najechaniu w podmenu */ +} + +/* Fokus w podmenu */ +.e-menu-container .e-menu .e-menu-item .e-ul .e-menu-item.e-focused { + background-color: #b3d9ff; /* Tło przy fokusie w podmenu */ +} + +/* Wybrany element w podmenu */ +.e-menu-container .e-menu .e-menu-item .e-ul .e-menu-item.e-selected { + background-color: #8ec6fe; /* Tło wybranego elementu w podmenu */ + color: #1a3c66; + font-weight: 600; +} + +/* Strzałka wskazująca podmenu */ +.e-menu-container .e-menu .e-menu-item .e-caret { + color: #1a3c66; /* Kolor strzałki */ +} + +/* Dostosowanie dla poziomego menu */ +.e-menu-container.e-horizontal .e-menu-item { + display: inline-block; /* Zapewnia poziomy układ */ +} + +/* Responsywność (opcjonalna) */ +@media (max-width: 768px) { + .e-menu-container .e-menu .e-menu-item { + font-size: 12px; /* Mniejszy tekst na urządzeniach mobilnych */ + padding: 6px 12px; + } +} diff --git a/OrdersManagementDataModel/Services/TaskSchedulerService.cs b/OrdersManagementDataModel/Services/TaskSchedulerService.cs index 33e4876..da1d151 100644 --- a/OrdersManagementDataModel/Services/TaskSchedulerService.cs +++ b/OrdersManagementDataModel/Services/TaskSchedulerService.cs @@ -11,8 +11,7 @@ public class TaskSchedulerService(OrdersManagementDbContext context, IMapper map public async Task> GetTaskSchedulers() { List taskSchedulers = - (await Task.FromResult(OrdersManagementQueries.GetSchedulers(context))).ToList(); - + await context.TaskSchedulers.Select(x => mapper.Map(x)).ToListAsync(); return taskSchedulers; }