bueno ahora se pueden modificar los clientes
This commit is contained in:
@@ -21,6 +21,46 @@ public class AdminController: ControllerBase
|
|||||||
return Ok(list);
|
return Ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("api/admin/cliente")]
|
||||||
|
public IActionResult ObtenerCliente([FromHeader(Name ="Auth")]string Auth, long dni = 0){
|
||||||
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||||
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
if (dni <= 0) return BadRequest(new { message = "No puede haber un dni 0 o menor"});
|
||||||
|
|
||||||
|
Cliente? cambio = RepositorioUsuarios.Singleton.ObtenerClientePorDni(dni);
|
||||||
|
if (cambio == null) BadRequest(new { message = "no hay un cliente por ese dni"});
|
||||||
|
|
||||||
|
UpdateUsuarioAdmin a = new UpdateUsuarioAdmin{
|
||||||
|
Apellido = cambio.Apellido,
|
||||||
|
Celular = cambio.Celular,
|
||||||
|
Domicilio = cambio.Domicilio,
|
||||||
|
Nombre = cambio.Nombre,
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("api/admin/cliente")]
|
||||||
|
public IActionResult PatchCliente([FromHeader(Name ="Auth")]string Auth, [FromBody]UpdateUsuarioAdmin dto, [FromQuery]long dni=0){
|
||||||
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||||
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
if (dni <= 0) return BadRequest(new { message = "No puede haber un dni 0 o menor"});
|
||||||
|
|
||||||
|
var validacion2 = checkdto(dto);
|
||||||
|
if (validacion2 != "") return BadRequest(new { message = validacion2});
|
||||||
|
|
||||||
|
Cliente?cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
if (cli == null) return Unauthorized();
|
||||||
|
|
||||||
|
bool ret = RepositorioUsuarios.Singleton.PatchUsuario(dto, dni, cli.Dni);
|
||||||
|
|
||||||
|
return ret?
|
||||||
|
Ok(new { message = "Se actualizaron los datos"}):
|
||||||
|
BadRequest(new { message = "Fallo al guardar los datos"});
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("api/admin/clientes/grupo")]
|
[HttpGet("api/admin/clientes/grupo")]
|
||||||
public IActionResult GetGruposByCliente([FromHeader(Name ="Auth")]string Auth, [FromQuery]long Dni){
|
public IActionResult GetGruposByCliente([FromHeader(Name ="Auth")]string Auth, [FromQuery]long Dni){
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
@@ -159,4 +199,13 @@ public class AdminController: ControllerBase
|
|||||||
int ret = RepositorioPropiedades.Singleton.CuantasPaginasBusqueda(cantidadHabitaciones, servicios, tipoPropiedad, 0);
|
int ret = RepositorioPropiedades.Singleton.CuantasPaginasBusqueda(cantidadHabitaciones, servicios, tipoPropiedad, 0);
|
||||||
return Ok(new { message = ret});
|
return Ok(new { message = ret});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string checkdto(UpdateUsuarioAdmin d){
|
||||||
|
string ret ="";
|
||||||
|
if (d.Nombre=="") ret+="Campo Nombre vacio\n";
|
||||||
|
if (d.Apellido=="") ret+="Campo Apellido vacio\n";
|
||||||
|
if (d.Celular=="") ret+="Campo Celular vacio\n";
|
||||||
|
if (d.Domicilio=="")ret+="Campo Domicilio vacio\n";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
8
Entidades/Admin/UpdateUsuarioAdmin.cs
Normal file
8
Entidades/Admin/UpdateUsuarioAdmin.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Entidades.Admin;
|
||||||
|
public class UpdateUsuarioAdmin {
|
||||||
|
public string Nombre { get; set; } = null!;
|
||||||
|
public string Apellido { get; set; } = null!;
|
||||||
|
public string Domicilio { get; set; } = null!;
|
||||||
|
public string Celular { get; set; } = null!;
|
||||||
|
|
||||||
|
}
|
||||||
54
Front/src/Componentes/ModalModificarPropietarios.svelte
Normal file
54
Front/src/Componentes/ModalModificarPropietarios.svelte
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { UpdateCliente } from "../types";
|
||||||
|
|
||||||
|
|
||||||
|
let {onCancel, onConfirm, datos}: {onCancel:()=>void, onConfirm:(a:UpdateCliente)=>void, datos:UpdateCliente} = $props();
|
||||||
|
|
||||||
|
let cli:UpdateCliente|any = $state({});
|
||||||
|
onMount(()=>{
|
||||||
|
cli.nombre = datos.nombre;
|
||||||
|
cli.dni = datos.dni;
|
||||||
|
cli.apellido = datos.apellido;
|
||||||
|
cli.domicilio = datos.domicilio;
|
||||||
|
cli.celular = datos.celular;
|
||||||
|
})
|
||||||
|
|
||||||
|
function handleConfirm(e: Event) {
|
||||||
|
e.preventDefault();
|
||||||
|
onConfirm(cli);
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="modal fade show d-block" tabindex="-1" style="background-color: rgba(0,0,0,0.5);">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Modificar Datos Cliente</h5>
|
||||||
|
<button type="button" class="btn-close" aria-label="Close" onclick={onCancel}></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="nombre" class="form-label">Nombre</label>
|
||||||
|
<input type="text" id="nombre" class="form-control" bind:value={cli.nombre} required />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="apellido" class="form-label">Apellido</label>
|
||||||
|
<input type="text" id="apellido" class="form-control" bind:value={cli.apellido} required />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="domicilio" class="form-label">Domicilio</label>
|
||||||
|
<input type="text" id="domicilio" class="form-control" bind:value={cli.domicilio} required />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="celular" class="form-label">Celular</label>
|
||||||
|
<input type="tel" id="celular" class="form-control" bind:value={cli.celular} required />
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary" onclick={(e)=>handleConfirm(e)}>Guardar</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||||
import type { Cliente, Grupo } from "../types";
|
import type { Cliente, Grupo, UpdateCliente } from "../types";
|
||||||
import {urlG} from "../stores/urlStore";
|
import {urlG} from "../stores/urlStore";
|
||||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
import { fade, fly } from "svelte/transition";
|
import { fade, fly } from "svelte/transition";
|
||||||
|
import ModalModificarPropietarios from "../Componentes/ModalModificarPropietarios.svelte";
|
||||||
|
import { CardLink } from "@sveltestrap/sveltestrap";
|
||||||
|
|
||||||
let Clientes: Cliente[] = $state([]);
|
let Clientes: Cliente[] = $state([]);
|
||||||
let Grupos:any[] = $state([]);
|
let Grupos:any[] = $state([]);
|
||||||
@@ -16,7 +18,10 @@
|
|||||||
let grupo:string = $state("");
|
let grupo:string = $state("");
|
||||||
let SelCliente: Cliente = $state(null);
|
let SelCliente: Cliente = $state(null);
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
|
cargaUsuarios();
|
||||||
|
});
|
||||||
|
async function cargaUsuarios(){
|
||||||
try{
|
try{
|
||||||
const response = await fetch($urlG+"/api/admin/clientes", {
|
const response = await fetch($urlG+"/api/admin/clientes", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -34,8 +39,7 @@
|
|||||||
modaldata = "fallo al intentar obtener la lista de clientes";
|
modaldata = "fallo al intentar obtener la lista de clientes";
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
async function cargaGrupos(cli: Cliente){
|
async function cargaGrupos(cli: Cliente){
|
||||||
try {
|
try {
|
||||||
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
||||||
@@ -140,6 +144,59 @@
|
|||||||
modaldata = "Falla la conexion al servidor";
|
modaldata = "Falla la conexion al servidor";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let showModificarCliente:boolean = $state(false);
|
||||||
|
let datoscli:UpdateCliente = $state({dni:0, apellido:"", celular:"", domicilio:"", nombre:""});
|
||||||
|
|
||||||
|
async function abrirModalModificarCliente(e: Event, cli: Cliente) {
|
||||||
|
e.stopPropagation();
|
||||||
|
try {
|
||||||
|
const r = await fetch($urlG+"/api/admin/cliente?dni="+cli.dni, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Auth": token||"",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let data = await r.json();
|
||||||
|
if (r.ok){
|
||||||
|
datoscli = data;
|
||||||
|
datoscli.dni = cli.dni;
|
||||||
|
showModificarCliente = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modaldata = data.message;
|
||||||
|
} catch {
|
||||||
|
modaldata = "Falla la conexion al servidor";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function patchCliente(a:UpdateCliente) {
|
||||||
|
if (a.apellido =="" || a.celular=="" || a.domicilio=="" || a.nombre==""){
|
||||||
|
modaldata = "Hay campos vacios";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let dto ={
|
||||||
|
apellido: a.apellido,
|
||||||
|
celular: a.celular,
|
||||||
|
domicilio: a.domicilio,
|
||||||
|
nombre: a.nombre,
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
const r = await fetch($urlG+"/api/admin/cliente?dni="+a.dni, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Auth": token||"",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dto),
|
||||||
|
});
|
||||||
|
let data = await r.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
if (r.ok) cargaUsuarios();
|
||||||
|
}catch{
|
||||||
|
modaldata = "Falla la conexion al servidor";
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<NavBarAutocompletable/>
|
<NavBarAutocompletable/>
|
||||||
@@ -148,13 +205,18 @@
|
|||||||
<ModalEstatico payload={modaldata} close={()=> !!(modaldata = "")}/>
|
<ModalEstatico payload={modaldata} close={()=> !!(modaldata = "")}/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if showModificarCliente}
|
||||||
|
<ModalModificarPropietarios datos={datoscli} onCancel={()=>!!(showModificarCliente = false)}
|
||||||
|
onConfirm={patchCliente}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="content-fluid align-items-start">
|
<div class="content-fluid align-items-start">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col" style="padding-right: 2px;">
|
<div class="col ms-2">
|
||||||
<BarraHorizontalConTexto text="Clientes"/>
|
<BarraHorizontalConTexto text="Clientes"/>
|
||||||
|
|
||||||
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
||||||
<table class="table table-responsive table-sm table-striped table-hover table-bordered">
|
<table class="table table-responsive table-striped table-hover table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Dni</th>
|
<th>Dni</th>
|
||||||
@@ -171,14 +233,17 @@
|
|||||||
<td>{cli.email}</td>
|
<td>{cli.email}</td>
|
||||||
<td>
|
<td>
|
||||||
{#if cli.habilitado}
|
{#if cli.habilitado}
|
||||||
<button class="btn btn-outline-warning" onclick={(e) => bajaCliente(e, cli)}>
|
<button class="btn btn-warning" onclick={(e) => bajaCliente(e, cli)}>
|
||||||
Baja
|
Baja
|
||||||
</button>
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="btn btn-outline-success" onclick={(e) => bajaCliente(e, cli)}>
|
<button class="btn btn-success" onclick={(e) => bajaCliente(e, cli)}>
|
||||||
Alta
|
Alta
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
<button class="btn btn-secondary" onclick={(e)=>abrirModalModificarCliente(e, cli)}>
|
||||||
|
Modificar
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
@@ -186,7 +251,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col"style="padding-left: 2px;">
|
<div class="col me-2 ps-0">
|
||||||
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado"/>
|
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado"/>
|
||||||
<table class="table table-striped table-responsive table-sm table-bordered">
|
<table class="table table-striped table-responsive table-sm table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -208,11 +273,11 @@
|
|||||||
{/each}
|
{/each}
|
||||||
{:else if SelCliente != null}
|
{:else if SelCliente != null}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">Este Cliente no tiene Grupos</td>
|
<td colspan="3">Este Cliente no tiene Grupos</td>
|
||||||
</tr>
|
</tr>
|
||||||
{:else}
|
{:else}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">Seleccione un cliente para ver sus grupos</td>
|
<td colspan="3">Seleccione un cliente para ver sus grupos</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
8
Front/src/types.d.ts
vendored
8
Front/src/types.d.ts
vendored
@@ -179,4 +179,12 @@ export type LogDetalleDto = {
|
|||||||
columna:string,
|
columna:string,
|
||||||
valorAnterior:string,
|
valorAnterior:string,
|
||||||
valorNuevo:string
|
valorNuevo:string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateCliente = {
|
||||||
|
dni:number,
|
||||||
|
nombre:string,
|
||||||
|
apellido:string,
|
||||||
|
domicilio:string,
|
||||||
|
celular:string,
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Text;
|
|||||||
using Entidades.Dto;
|
using Entidades.Dto;
|
||||||
using Entidades;
|
using Entidades;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Entidades.Admin;
|
||||||
|
|
||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
|
|
||||||
@@ -186,4 +187,18 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
|||||||
if (cli == null|| cli.Dni == 0) return null;
|
if (cli == null|| cli.Dni == 0) return null;
|
||||||
return cli;
|
return cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool PatchUsuario(UpdateUsuarioAdmin dto, long dni, long responsabledni) {
|
||||||
|
var con = Context;
|
||||||
|
var usu = con.Clientes.FirstOrDefault(x=>x.Dni ==dni);
|
||||||
|
if (usu == null) return false;
|
||||||
|
|
||||||
|
usu.Nombre = dto.Nombre;
|
||||||
|
usu.Apellido = dto.Apellido;
|
||||||
|
usu.Celular = dto.Celular;
|
||||||
|
usu.Domicilio = dto.Domicilio;
|
||||||
|
|
||||||
|
GenerarLog(con, responsabledni, "Patch Usuario");
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user