@page "/ValorNomina" @page "/ValorNomina/{cl}" @using BlazorBootstrap @using GestionPersonalWeb.Components.Pages.FicherosMaestros.TipoPuestoTrabajoComponents @using Newtonsoft.Json @using GestionPersonalWeb.Components.Layout @using Microsoft.AspNetCore.WebUtilities @using GestionPersonalWeb.Components.Pages.InfoPersComponents @using GestionPersonalWeb.Models @using System.Linq.Expressions @using Serialize.Linq.Serializers @using System.Net.Http.Headers @using bdAntifraude.clases @using bdAntifraude.db @using System.Reflection @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @inject IJSRuntime JSRuntime @inject IJSRuntime JS @rendermode InteractiveServer @inject NavigationManager NavigationManager @inject IHttpClientFactory HttpClientFactory @inject IHttpContextAccessor HttpContextAccessor @inject UserState UserState @inject ProtectedSessionStorage ProtectedSessionStore @inject NavigationManager Navigation @*
Tipo puesto de trabajo: @puestoTrabajo.DESCRIPCION
*@
Valor Nomina
Sueldos
Sueldos Extra
Trienio Administración
Trienio Administración Extra
Trienio Oficina Antifraude
Trienio Oficina Antifraude Extra
Complemento Carrera Tramo I
Complemento Carrera Tramo II
Complemento Carrera Tramo III
Complemento Carrera Tramo IV
Complemento Carrera Tramo V
@code { [Parameter] public string? cl { get; set; } = ""; private static bdAntifraude.db.VALORESNOMINA oValorNomina = new VALORESNOMINA(); private EditContext editContext = new EditContext(oValorNomina); private HttpClient cliente = new HttpClient(); private ValidationMessageStore? messageStore; private string errorMessage = ""; List mensajes = new List(); public bool mostrar { get; set; } = true; public bool mostrarBtn { get; set; } = false; protected override async Task OnInitializedAsync() { try { var url = NavigationManager.ToAbsoluteUri(NavigationManager.Uri); cliente = Utilidades.ObtenerCliente(UserState.Token, HttpClientFactory); if (QueryHelpers.ParseQuery(url.Query).TryGetValue("cl", out var clValue)) { cl = clValue; } if (string.IsNullOrEmpty(cl)) { oValorNomina = new VALORESNOMINA(); mostrarBtn = true; } else { // ListaSexos = await Utilidades.ObtenerObjeto>(cliente, "/api/ENUMERACIONES/EnumeracionesGrupo/SEXO"); string idDesencriptado = Utilidades.Desencriptar(cl); int id = int.Parse(idDesencriptado); var response = await cliente.GetAsync($"/api/VALORESNOMINA/{id}"); if (!response.IsSuccessStatusCode) { throw new Exception($"Error al obtener los datos del Tipo de Trabajo. Código: {response.StatusCode}"); } var resultContent = await response.Content.ReadAsStringAsync(); oValorNomina = JsonConvert.DeserializeObject(resultContent) ?? throw new Exception("Error al deserializar los datos."); } editContext = new EditContext(oValorNomina); messageStore = new ValidationMessageStore(editContext); mostrar = false; } catch (Exception ex) { errorMessage = ex.Message; Console.WriteLine($"Error durante la inicialización: {ex.Message}"); mostrar = false; } finally { mostrar = false; } } private async Task GuardarPuestoTrabajo() { cliente = Utilidades.ObtenerCliente(UserState.Token, HttpClientFactory); if (!editContext.GetValidationMessages().Any()) { if (oValorNomina.IDVALNOMINA == 0)//Nuevo { var response = await Utilidades.NuevoObjeto(cliente, "/api/VALORESNOMINA", oValorNomina, mensajes); if (response != null) { oValorNomina = response; } else { mensajes.Add(new ToastMessage { Type = ToastType.Success, Message = $"Guardado Correctamente.", }); } await InvokeAsync(StateHasChanged); } else//Guardar { var response = await Utilidades.ActualizarObjeto(cliente, "/api/VALORESNOMINA/" + oValorNomina.IDVALNOMINA, oValorNomina, mensajes); } } else { mensajes.Add(new ToastMessage { Type = ToastType.Danger, Message = Utilidades.ListaErroresHtml(editContext.GetValidationMessages()), }); } } }