From 559de37672b7c507d8263192b174f96318697d87 Mon Sep 17 00:00:00 2001 From: Leandro Hernan Rojas Date: Sun, 6 Apr 2025 02:43:01 -0300 Subject: [PATCH] Update UI Blazor Add Customers --- Domain/Entities/ECustomer.cs | 1 - Models/Helpers/PaginationExtensions.cs | 5 - phronCare.UIBlazor/Data/PagedResult.cs | 10 ++ .../Pages/Sales/Customers.razor | 113 ++++++++++++++++++ phronCare.UIBlazor/Program.cs | 2 + .../Services/Sales/CustomerHttpService.cs | 25 ++++ .../Services/Sales/CustomerSearchParams.cs | 11 ++ 7 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 phronCare.UIBlazor/Data/PagedResult.cs create mode 100644 phronCare.UIBlazor/Pages/Sales/Customers.razor create mode 100644 phronCare.UIBlazor/Services/Sales/CustomerHttpService.cs create mode 100644 phronCare.UIBlazor/Services/Sales/CustomerSearchParams.cs diff --git a/Domain/Entities/ECustomer.cs b/Domain/Entities/ECustomer.cs index c98c093..5dcc679 100644 --- a/Domain/Entities/ECustomer.cs +++ b/Domain/Entities/ECustomer.cs @@ -32,6 +32,5 @@ namespace Domain.Entities public virtual ICollection PhSCustomerDocuments { get; set; } = new List(); - //public virtual ICollection PhSQuoteHeaders { get; set; } = new List(); } } diff --git a/Models/Helpers/PaginationExtensions.cs b/Models/Helpers/PaginationExtensions.cs index 9cd5123..9f16a75 100644 --- a/Models/Helpers/PaginationExtensions.cs +++ b/Models/Helpers/PaginationExtensions.cs @@ -1,10 +1,5 @@ using Domain.Generics; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Models.Helpers { diff --git a/phronCare.UIBlazor/Data/PagedResult.cs b/phronCare.UIBlazor/Data/PagedResult.cs new file mode 100644 index 0000000..c249dd6 --- /dev/null +++ b/phronCare.UIBlazor/Data/PagedResult.cs @@ -0,0 +1,10 @@ +namespace phronCare.UIBlazor.Data +{ + public class PagedResult + { + public IEnumerable Items { get; set; } + public int TotalItems { get; set; } + public int Page { get; set; } + public int PageSize { get; set; } + } +} diff --git a/phronCare.UIBlazor/Pages/Sales/Customers.razor b/phronCare.UIBlazor/Pages/Sales/Customers.razor new file mode 100644 index 0000000..31fcd32 --- /dev/null +++ b/phronCare.UIBlazor/Pages/Sales/Customers.razor @@ -0,0 +1,113 @@ +@page "/customers" +@using phronCare.UIBlazor.Services.Sales +@using phronCare.UIBlazor.Data + + +@inject CustomerHttpService CustomerService + +

Buscar Clientes

+ +
+ + + + +
+ +@if (PagedResult != null) +{ + + + + + + + + + + + + + + + + + + @foreach (var c in PagedResult.Items) + { + var addr = c.PhSCustomerAddresses.FirstOrDefault(); + var doc = c.PhSCustomerDocuments.FirstOrDefault(); + + + + + + + + + + + + + + } + +
IdNameBusinessNameActiveExternalCodeHasCreditAccountCreditLimitEmailPhoneDirecciónDocumento
@c.Id@c.Name@c.BusinessName@(c.Active ? "Sí" : "No")@c.ExternalCode@(c.HasCreditAccount ? "Sí" : "No")@c.CreditLimit@addr?.Email@addr?.Phonenumber + @addr?.Streetaddress1 @addr?.Streetaddress2
+ @addr?.City, @addr?.Postalcode, @addr?.Country +
+ @doc?.DocumentNumber
+ @doc?.IssueDate?.ToString("yyyy-MM-dd")
+ @doc?.ExpiryDate?.ToString("yyyy-MM-dd") +
+ +
+ + Página @SearchParams.Page de @TotalPaginas + +
+} +else +{ +

No hay resultados.

+} + +@code { + private CustomerSearchParams SearchParams = new(); + private PagedResult? PagedResult; + + private async Task BuscarClientes() + { + SearchParams.Page = 1; // reset al buscar + await CargarClientes(); + } + + private async Task CargarClientes() + { + // pagedResult = await CustomerHttpService.searcs(SearchParams); + } + + private async Task SiguientePagina() + { + if (PuedeAvanzar) + { + SearchParams.Page++; + await CargarClientes(); + } + } + + private async Task AnteriorPagina() + { + if (PuedeRetroceder) + { + SearchParams.Page--; + await CargarClientes(); + } + } + + private int TotalPaginas => PagedResult is null ? 1 : + (int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize); + + private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas; + private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1; +} diff --git a/phronCare.UIBlazor/Program.cs b/phronCare.UIBlazor/Program.cs index 8fd5a11..b71fd6e 100644 --- a/phronCare.UIBlazor/Program.cs +++ b/phronCare.UIBlazor/Program.cs @@ -8,6 +8,7 @@ using Blazored.Modal; using Blazored.Toast; using phronCare.UIBlazor.Services.Tickets; using phronCare.UIBlazor.Shared; +using phronCare.UIBlazor.Services.Sales; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); @@ -38,6 +39,7 @@ if (config != null) #endregion #region Injection Dependencis builder.Services.AddScoped(); +builder.Services.AddScoped(); #endregion #region UI builder.Services.AddBlazoredModal(); diff --git a/phronCare.UIBlazor/Services/Sales/CustomerHttpService.cs b/phronCare.UIBlazor/Services/Sales/CustomerHttpService.cs new file mode 100644 index 0000000..38eb685 --- /dev/null +++ b/phronCare.UIBlazor/Services/Sales/CustomerHttpService.cs @@ -0,0 +1,25 @@ +using Domain.Entities; +using Domain.Generics; +using System.Net.Http.Json; +namespace phronCare.UIBlazor.Services.Sales +{ + public class CustomerHttpService + { + private readonly HttpClient _http; + public CustomerHttpService(HttpClient http) + { + _http = http; + } + public async Task?> SearchCustomersAsync(CustomerSearchParams searchParams) + { + var url = $"api/Customer/SearchPaged?" + + $"name={searchParams.Name}&" + + $"email={searchParams.Email}&" + + $"document={searchParams.Document}&" + + $"page={searchParams.Page}&" + + $"pageSize={searchParams.PageSize}"; + return await _http.GetFromJsonAsync>(url); + } + } + +} diff --git a/phronCare.UIBlazor/Services/Sales/CustomerSearchParams.cs b/phronCare.UIBlazor/Services/Sales/CustomerSearchParams.cs new file mode 100644 index 0000000..495bb06 --- /dev/null +++ b/phronCare.UIBlazor/Services/Sales/CustomerSearchParams.cs @@ -0,0 +1,11 @@ +namespace phronCare.UIBlazor.Services.Sales +{ + public class CustomerSearchParams + { + public string? Name { get; set; } + public string? Email { get; set; } + public string? Document { get; set; } + public int Page { get; set; } = 1; + public int PageSize { get; set; } = 10; + } +}