termine lo que corresponde a logear los contratos

This commit is contained in:
2025-01-13 17:59:21 -03:00
parent 062b97515f
commit a19d2b2a42
5 changed files with 51 additions and 6 deletions

View File

@@ -34,6 +34,16 @@ public class NotificacionesController: ControllerBase {
return Ok(noti);
}
[HttpGet("api/notificaciones/haySinLeer")]
public IActionResult GetHayNotis([FromHeader(Name ="Auth")]string Auth) {
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
var cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
if (cli == null) return BadRequest(new {message = "Fallo al intentar encontrar tu usuario (puede que te hayas logeado desde otro dispositivo?)"});
bool ret = RepositorioNotificaciones.Singleton.HayNotis(cli.Dni);
return Ok(new {message = ret});
}
[HttpPut("api/notificaciones")]
public IActionResult MarcarComoLeido([FromHeader(Name = "Auth")]string Auth, NotificacionMarcarLeidoDto nota) {

View File

@@ -41,7 +41,7 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Contrato</h5>
<button type="button" class="btn-close" onclick={onClose}></button>
<button type="button" class="btn-close" onclick={onClose} aria-label="Cerrar"></button>
</div>
<div class="modal-body">

View File

@@ -10,7 +10,8 @@
import { navigate } from "svelte-routing";
let isOpen: boolean = $state(false);
let hayNotis:boolean = $state(false);
const permisos = writable<Grupo[]>([]);
const email = localStorage.getItem('email');
const token = sessionStorage.getItem('token');
@@ -38,8 +39,28 @@
onMount( () => {
obtenerPermisos();
obtenerNotis();
})
async function obtenerNotis() {
try {
const responce = await fetch($urlG+"/api/notificaciones/haySinLeer", {
method: "GET",
headers: {
"Auth": String(token)
}
});
if(responce.ok) {
let data = await responce.json();
hayNotis = data.message;
return;
}
} catch (e) {
console.error(e);
}
}
function redirijir(path: string){
navigate(path);
}
@@ -70,8 +91,15 @@
<img src="/toggle-right.svg" alt=""/>
{/if}
</button>
<button class="badge btn btn-info" onclick={()=>navigate("/notificaciones")}>
<img src="/bell.svg" alt="">
<button class="badge btn btn-info position-relative" onclick={()=>navigate("/notificaciones")}>
<img src="/bell.svg" alt="">
{#if hayNotis}
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
!
<span class="visually-hidden">unread messages</span>
</span>
{/if}
</button>
</div>
<NavbarToggler on:click={() => (isOpen = !isOpen)} />

View File

@@ -127,8 +127,8 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
Monto = cont.IdpropiedadNavigation.Monto,
Pagado = 0,
};
can.Id = (con.Canons.Any()? con.Canons.Max(x=>x.Id) :0)+1;
can.Idcontratos.Add(cont);
can.Id = (con.Canons.Any()? con.Canons.Count() :0)+1+i;
con.Canons.Add(can);
cont.Idcanons.Add(can);

View File

@@ -4,6 +4,7 @@ using Entidades.Dto;
using Entidades;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using Org.BouncyCastle.Math.EC.Rfc7748;
namespace Modelo;
@@ -35,4 +36,10 @@ public class RepositorioNotificaciones : RepositorioBase<RepositorioNotificacion
.Where(x => x.Dnicliente == dni);
return notis;
}
public bool HayNotis(long dni) {
var con = Context;
bool hay = con.Notificaciones.Where(x=>x.Leido == false).Any();
return hay;
}
}