From 7660db1c0b85644eb167eae2b7dfd33560d5f8b1 Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Sat, 12 Apr 2025 07:12:14 +0200 Subject: [PATCH] * Added managing EdiCustomerOrderTranslations --- ...EdiCustomerOrdersTranslationsController.cs | 24 +++++ .../Controllers/HangfireJobsController.cs | 2 - FaKrosnoApi/Program.cs | 1 + .../Components/Layout/MainLayout.razor | 2 +- .../Pages/CustomerOrdersTranslations.razor | 96 +++++++++++++++++++ OrdersManagement/Program.cs | 1 + .../EdiCustomerOrderTranslateService.cs | 29 ++++++ .../EdiCustomerOrderTranslateService.cs | 24 +++++ .../IEdiCustomerOrderTranslateService.cs | 9 ++ 9 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 FaKrosnoApi/Controllers/EdiCustomerOrdersTranslationsController.cs create mode 100644 OrdersManagement/Components/Pages/CustomerOrdersTranslations.razor create mode 100644 OrdersManagement/Services/EdiCustomerOrderTranslateService.cs create mode 100644 SytelineSaAppEfDataModel/Services/EdiCustomerOrderTranslateService.cs create mode 100644 SytelineSaAppEfDataModel/Services/IEdiCustomerOrderTranslateService.cs diff --git a/FaKrosnoApi/Controllers/EdiCustomerOrdersTranslationsController.cs b/FaKrosnoApi/Controllers/EdiCustomerOrdersTranslationsController.cs new file mode 100644 index 0000000..128b092 --- /dev/null +++ b/FaKrosnoApi/Controllers/EdiCustomerOrdersTranslationsController.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Mvc; +using SytelineSaAppEfDataModel.Dtos; +using SytelineSaAppEfDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class EdiCustomerOrdersTranslationsController(IEdiCustomerOrderTranslateService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable ediCustomerOrdersTranlations = await service.GetAll(); + return Ok(ediCustomerOrdersTranlations); + } + + [HttpDelete] + public async Task Delete([FromQuery] int id) + { + await service.Delete(id); + return NoContent(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/HangfireJobsController.cs b/FaKrosnoApi/Controllers/HangfireJobsController.cs index 54725ed..86e89d0 100644 --- a/FaKrosnoApi/Controllers/HangfireJobsController.cs +++ b/FaKrosnoApi/Controllers/HangfireJobsController.cs @@ -90,8 +90,6 @@ public class HangfireJobsController( [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) diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index 6828f42..d0e531f 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -89,6 +89,7 @@ builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSa builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/OrdersManagement/Components/Layout/MainLayout.razor b/OrdersManagement/Components/Layout/MainLayout.razor index f054e55..1906219 100644 --- a/OrdersManagement/Components/Layout/MainLayout.razor +++ b/OrdersManagement/Components/Layout/MainLayout.razor @@ -12,7 +12,7 @@
-
+
Icon

FA Krosno Manager

diff --git a/OrdersManagement/Components/Pages/CustomerOrdersTranslations.razor b/OrdersManagement/Components/Pages/CustomerOrdersTranslations.razor new file mode 100644 index 0000000..361b150 --- /dev/null +++ b/OrdersManagement/Components/Pages/CustomerOrdersTranslations.razor @@ -0,0 +1,96 @@ +@page "/CustomerOrdersTranslations" + +@using SytelineSaAppEfDataModel.Dtos +@using Syncfusion.Blazor.Cards +@using Syncfusion.Blazor.Grids +@using Action = Syncfusion.Blazor.Grids.Action + +@inject EdiCustomerOrderTranslateService EdiCustomerOrderTranslateService + +
+ + +

Zarządzanie powiązaniami zamówień z DELFORami

+
+ + + + + + + + + + + + + + + + + + + FA Krosno Manager © @(DateTime.Now.Year) + +
+
+ +@code { + private List OrderTranslations { get; set; } = new(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { + await LoadTranslations(); + StateHasChanged(); + // } + } + } + + public async Task OnActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await EdiCustomerOrderTranslateService.DeleteEdiCustomerOrderTranslateAsync(args.Data); + } + } + + private async Task LoadTranslations() + { + OrderTranslations = (await EdiCustomerOrderTranslateService.GetEdiCustomerOrdersTranslationsAsync() ?? Array.Empty()).OrderByDescending(x => x.CreatedDate).ToList(); + } + + private async Task OnActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadTranslations(); + break; + } + } + +} \ No newline at end of file diff --git a/OrdersManagement/Program.cs b/OrdersManagement/Program.cs index 1d93dca..2a820f3 100644 --- a/OrdersManagement/Program.cs +++ b/OrdersManagement/Program.cs @@ -44,6 +44,7 @@ builder.Services.AddRazorComponents() builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/OrdersManagement/Services/EdiCustomerOrderTranslateService.cs b/OrdersManagement/Services/EdiCustomerOrderTranslateService.cs new file mode 100644 index 0000000..2396cb7 --- /dev/null +++ b/OrdersManagement/Services/EdiCustomerOrderTranslateService.cs @@ -0,0 +1,29 @@ +using SytelineSaAppEfDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class EdiCustomerOrderTranslateService( + IHttpClientFactory httpClientFactory, + CustomAuthenticationStateProvider authenticationStateProvider) + : ServiceBase(httpClientFactory, authenticationStateProvider) +{ + public async Task?> GetEdiCustomerOrdersTranslationsAsync() + { + try + { + return await GetListAsync("api/EdiCustomerOrdersTranslations"); + } + catch (HttpRequestException ex) + { + Console.WriteLine($"Błąd HTTP w GetEdiCustomerOrdersTranslationsAsync: {ex.Message}"); + return null; + } + } + + public async Task DeleteEdiCustomerOrderTranslateAsync(EdiCustomerOrderTranslateDto ediCustomerOrderTranslateDto) + { + HttpResponseMessage responseMessage = + await DeleteAsync($"api/EdiCustomerOrdersTranslations/?id={ediCustomerOrderTranslateDto.Id}"); + return responseMessage.IsSuccessStatusCode ? 1 : 0; + } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/EdiCustomerOrderTranslateService.cs b/SytelineSaAppEfDataModel/Services/EdiCustomerOrderTranslateService.cs new file mode 100644 index 0000000..17955f1 --- /dev/null +++ b/SytelineSaAppEfDataModel/Services/EdiCustomerOrderTranslateService.cs @@ -0,0 +1,24 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using SytelineSaAppEfDataModel.Dtos; + +namespace SytelineSaAppEfDataModel.Services; + +public class EdiCustomerOrderTranslateService(SytelineSaAppDbContext context, IMapper mapper) : IEdiCustomerOrderTranslateService +{ + public async Task> GetAll() + { + return await context.EdiCustomerOrderTranslates.Select(x => mapper.Map(x)) + .ToListAsync(); + } + + public async Task Delete(int id) + { + var entity = await context.EdiCustomerOrderTranslates.FindAsync(id); + if (entity != null) + { + context.EdiCustomerOrderTranslates.Remove(entity); + await context.SaveChangesAsync(); + } + } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderTranslateService.cs b/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderTranslateService.cs new file mode 100644 index 0000000..b7258ec --- /dev/null +++ b/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderTranslateService.cs @@ -0,0 +1,9 @@ +using SytelineSaAppEfDataModel.Dtos; + +namespace SytelineSaAppEfDataModel.Services; + +public interface IEdiCustomerOrderTranslateService +{ + Task> GetAll(); + Task Delete(int id); +} \ No newline at end of file