Ajuste Revision 2 Usuarios

This commit is contained in:
Dario F. Gomez Z 2023-11-07 08:35:29 -05:00
parent 39db90fc07
commit f97a42f296
5 changed files with 165 additions and 22 deletions

View File

@ -22,7 +22,8 @@ namespace MSAdminUsuarios.Context
public virtual DbSet<PERFIL> PERFILESMs { get; set; } = null!; public virtual DbSet<PERFIL> PERFILESMs { get; set; } = null!;
public virtual DbSet<PERFILPORUSUARIO> PERFILESPORUSUARIOs { get; set; } = null!; public virtual DbSet<PERFILPORUSUARIO> PERFILESPORUSUARIOs { get; set; } = null!;
public virtual DbSet<USUARIO> USUARIOSMs { get; set; } = null!; public virtual DbSet<USUARIO> USUARIOSMs { get; set; } = null!;
public virtual DbSet<CORREOSAREAMS> CORREOSAREAMS { get; set; } = null!; public virtual DbSet<CORREOSAREAMS> CORREOSAREAMS { get; set; } = null!;
public virtual DbSet<USUARIOSTEMP> USUARIOSTEMP { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
@ -48,7 +49,7 @@ namespace MSAdminUsuarios.Context
} }
else else
{ {
modelBuilder.HasDefaultSchema("ADMIN"); modelBuilder.HasDefaultSchema("ADMIN");
} }
@ -109,6 +110,40 @@ namespace MSAdminUsuarios.Context
}); });
modelBuilder.Entity<USUARIOSTEMP>(entity =>
{
entity.HasKey(e => e.NU_PK_USUTMP)
.HasName("USUARIOSTEMP_PK");
entity.ToTable("USUARIOSTEMP");
entity.Property(e => e.NU_PK_USUTMP).HasPrecision(10);
entity.Property(e => e.FE_INICIOACTIVACION_USUTMP).HasColumnType("DATE");
entity.Property(e => e.FE_FINACTIVACION_USUTMP).HasColumnType("DATE");
entity.Property(e => e.NU_ESTADO_USUTMP).HasPrecision(10);
entity.Property(e => e.NU_TIPODOC_USUTMP).HasPrecision(10);
entity.Property(e => e.TX_CORREO_USUTMP).HasMaxLength(200);
entity.Property(e => e.TX_IDENTIFICACION_USUTMP).HasMaxLength(100);
entity.Property(e => e.TX_NOMBREPVD_USUTMP).HasMaxLength(1999);
entity.Property(e => e.TX_PRIMERAPELL_USUTMP).HasMaxLength(200);
entity.Property(e => e.TX_PRIMERNOM_USUTMP).HasMaxLength(200);
entity.Property(e => e.TX_SEGUNDOAPELL_USUTMP).HasMaxLength(200);
entity.Property(e => e.TX_SEGUNDONOM_USUTMP).HasMaxLength(200);
entity.Property(e => e.TX_TELEFONO_USUTMP).HasMaxLength(100);
});
OnModelCreatingPartial(modelBuilder); OnModelCreatingPartial(modelBuilder);
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace MSAdminUsuarios.Context
{
public partial class USUARIOSTEMP
{
public int NU_PK_USUTMP { get; set; }
public int? NU_TIPODOC_USUTMP { get; set; }
public string? TX_IDENTIFICACION_USUTMP { get; set; }
public string? TX_PRIMERNOM_USUTMP { get; set; }
public string? TX_SEGUNDONOM_USUTMP { get; set; }
public string? TX_PRIMERAPELL_USUTMP { get; set; }
public string? TX_SEGUNDOAPELL_USUTMP { get; set; }
public string? TX_NOMBREPVD_USUTMP { get; set; }
public string? TX_CORREO_USUTMP { get; set; }
public string? TX_TELEFONO_USUTMP { get; set; }
public int? NU_ESTADO_USUTMP { get; set; }
public DateTime? FE_INICIOACTIVACION_USUTMP { get; set; }
public DateTime? FE_FINACTIVACION_USUTMP { get; set; }
}
}

View File

@ -32,6 +32,7 @@ namespace MSAdminUsuarios.Controllers
if (login.TX_PASSWORD_USUMS == null) return BadRequest("Es necesario ingresar una contrase<73>a"); if (login.TX_PASSWORD_USUMS == null) return BadRequest("Es necesario ingresar una contrase<73>a");
USUARIO? userldap = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS); USUARIO? userldap = _context.USUARIOSMs.FirstOrDefault(u => u.TX_LOGINNAME_USUMS == login.TX_LOGINNAME_USUMS);
if (userldap == null) return BadRequest("usuario");
if(userldap.BL_VIENELDAP_USUMS == 1) if(userldap.BL_VIENELDAP_USUMS == 1)
{ {
bool boolldap = LoginLib.Login(login.TX_LOGINNAME_USUMS, login.TX_PASSWORD_USUMS); bool boolldap = LoginLib.Login(login.TX_LOGINNAME_USUMS, login.TX_PASSWORD_USUMS);

View File

@ -0,0 +1,70 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MSAdminUsuarios.Context;
using MSAdminUsuarios.Models;
namespace MSAdminUsuarios.Controllers
{
[Route("[controller]")]
[ApiController]
public class UsuariosTempController : ControllerBase
{
private readonly ModelContext _context;
private readonly ILogger<UsuariosTempController> _logger;
private ErrorModel _errorModel;
public UsuariosTempController(ModelContext context, ILogger<UsuariosTempController> logger)
{
_context = context;
_logger = logger;
_errorModel = new ErrorModel();
}
[HttpGet]
public async Task<IActionResult> Get()
{
_errorModel = new ErrorModel();
try
{
List<USUARIOSTEMP> externos = await _context.USUARIOSTEMP.OrderBy(q => q.NU_PK_USUTMP).ToListAsync();
return Ok(externos);
}
catch (Exception)
{
_errorModel.error = true;
_errorModel.cuerpo.Add("Error con la base de datos.");
return BadRequest(_errorModel);
}
}
[HttpPost]
public async Task<IActionResult> Post(USUARIOSTEMP nuevo)
{
_errorModel = new ErrorModel();
try
{
if (nuevo == null)
{
_errorModel.error = true;
_errorModel.cuerpo.Add("No se envió solicitud.");
return Conflict(_errorModel);
}
_context.USUARIOSTEMP.Add(nuevo);
await _context.SaveChangesAsync();
_errorModel.error = false;
_errorModel.cuerpo.Add("Solicitud de usuario temporal guardado correctamente.");
return Ok(_errorModel);
}
catch (Exception)
{
_errorModel.error = true;
_errorModel.cuerpo.Add("Error con la base de datos.");
return BadRequest(_errorModel);
}
}
}
}

View File

@ -66,6 +66,12 @@ namespace MSAdminUsuarios.Utils
); );
} }
channel.QueueBind(
queue: $"{exchangeName}.Usuarios",
exchange: exchangeName,
routingKey: $"{exchangeName}.Usuarios.*.*"
);
return channel; return channel;
} }
@ -74,37 +80,46 @@ namespace MSAdminUsuarios.Utils
RabbitMQConfig mqConfig = builder.Configuration.GetSection("RabbitMQConfig").Get<RabbitMQConfig>(); RabbitMQConfig mqConfig = builder.Configuration.GetSection("RabbitMQConfig").Get<RabbitMQConfig>();
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().AddEventLog()); var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().AddEventLog());
//var logger = loggerFactory.CreateLogger("Rabbit2"); try
//logger.LogInformation("Inicia Rabbitmq con");
ConnectionFactory factory = new()
{ {
HostName = mqConfig.HostName, //var logger = loggerFactory.CreateLogger("Rabbit2");
UserName = mqConfig.UserName, //logger.LogInformation("Inicia Rabbitmq con");
Password = mqConfig.Password,
};
IConnection connection = factory.CreateConnection(); ConnectionFactory factory = new()
IModel channel = connection.CreateModel(); {
HostName = mqConfig.HostName,
UserName = mqConfig.UserName,
Password = mqConfig.Password,
};
EventingBasicConsumer consumer = new(channel); IConnection connection = factory.CreateConnection();
IModel channel = connection.CreateModel();
consumer.Received += RabbitMQService.ConsumeRabbitMQEvent; EventingBasicConsumer consumer = new(channel);
List<string> queues = new() consumer.Received += RabbitMQService.ConsumeRabbitMQEvent;
List<string> queues = new()
{ {
$"{projectName}.PerfilesPorUsuario", $"{projectName}.PerfilesPorUsuario",
$"{projectName}.Usuarios", $"{projectName}.Usuarios",
}; };
foreach (var queue in queues) foreach (var queue in queues)
{ {
channel.BasicConsume( channel.BasicConsume(
queue: queue, queue: queue,
autoAck: false, autoAck: false,
consumer: consumer consumer: consumer
); );
}
} }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
} }