Merge branch 'master' of http://181.204.191.98:8003/MIHIMS/Apigateway
This commit is contained in:
commit
e7cef89586
@ -1,5 +1,6 @@
|
|||||||
using LdapLoginLib.Data;
|
using LdapLoginLib.Data;
|
||||||
using LdapLoginLib.Models;
|
using LdapLoginLib.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System.DirectoryServices.Protocols;
|
using System.DirectoryServices.Protocols;
|
||||||
|
|
||||||
namespace LdapLoginLib
|
namespace LdapLoginLib
|
||||||
@ -7,11 +8,13 @@ namespace LdapLoginLib
|
|||||||
public class LDAP
|
public class LDAP
|
||||||
{
|
{
|
||||||
private static readonly LdapConfig _ldap = new();
|
private static readonly LdapConfig _ldap = new();
|
||||||
|
private readonly ILogger<LDAP> _logger;
|
||||||
|
|
||||||
//public LDAP()
|
public LDAP(ILogger<LDAP> logger)
|
||||||
//{
|
{
|
||||||
// _ldap = new LdapConfig();
|
_logger = logger;
|
||||||
//}
|
//_ldap = new LdapConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public bool Login(string password, string? document = null, string? username = null, string? email = null)
|
public bool Login(string password, string? document = null, string? username = null, string? email = null)
|
||||||
{
|
{
|
||||||
@ -25,6 +28,8 @@ namespace LdapLoginLib
|
|||||||
username: username,
|
username: username,
|
||||||
email: email);
|
email: email);
|
||||||
|
|
||||||
|
_logger.LogInformation("Ingreso: " + userInfo.NumeroDocumento + " - " + userInfo.Usuario + " - " + userInfo.Correo);
|
||||||
|
|
||||||
//Si el usuario está inactivo...
|
//Si el usuario está inactivo...
|
||||||
if (userInfo.Activo == false) return false;
|
if (userInfo.Activo == false) return false;
|
||||||
|
|
||||||
@ -42,6 +47,7 @@ namespace LdapLoginLib
|
|||||||
catch (LdapException ldapEx)
|
catch (LdapException ldapEx)
|
||||||
{
|
{
|
||||||
//Console.WriteLine($"Authentication failed: {ldapEx.Message}");
|
//Console.WriteLine($"Authentication failed: {ldapEx.Message}");
|
||||||
|
_logger.LogError(ldapEx.ErrorCode + " // " + ldapEx.Message);
|
||||||
throw new Exception(_getErrorMessage(ldapEx.ErrorCode, ldapEx.Message));
|
throw new Exception(_getErrorMessage(ldapEx.ErrorCode, ldapEx.Message));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
|
||||||
<PackageReference Include="RawScape.Nini" Version="1.0.0" />
|
<PackageReference Include="RawScape.Nini" Version="1.0.0" />
|
||||||
<PackageReference Include="System.DirectoryServices.Protocols" Version="6.0.2" />
|
<PackageReference Include="System.DirectoryServices.Protocols" Version="6.0.2" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||||
|
@ -17,11 +17,19 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ModelContext _context;
|
private readonly ModelContext _context;
|
||||||
private readonly Encripter _encript = new();
|
private readonly Encripter _encript = new();
|
||||||
private readonly LDAP _ldap = new();
|
private readonly LDAP _ldap;
|
||||||
|
|
||||||
public AuthController(ModelContext context)
|
public AuthController(ModelContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
var loggerFactory = LoggerFactory.Create(builder =>
|
||||||
|
{
|
||||||
|
builder.AddConsole();
|
||||||
|
});
|
||||||
|
|
||||||
|
var logger = loggerFactory.CreateLogger<LDAP>();
|
||||||
|
|
||||||
|
_ldap = new LDAP(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("Login")]
|
[HttpPost("Login")]
|
||||||
@ -29,7 +37,7 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_encript.IsValid) return BadRequest("Lectura inv<EFBFBD>lida");
|
if (!_encript.IsValid) return BadRequest("Lectura inválida");
|
||||||
|
|
||||||
if (login.TX_LOGINNAME_USUMS == null) return BadRequest("Es necesario ingresar un usuario");
|
if (login.TX_LOGINNAME_USUMS == null) return BadRequest("Es necesario ingresar un usuario");
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MSAdminUsuarios.Context;
|
using MSAdminUsuarios.Context;
|
||||||
|
using MSAdminUsuarios.Models;
|
||||||
using Security;
|
using Security;
|
||||||
|
|
||||||
namespace MSAdminUsuarios.Controllers
|
namespace MSAdminUsuarios.Controllers
|
||||||
@ -32,13 +33,15 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult post([FromBody] CORREOSAREAMS nuevo)
|
public IActionResult post([FromBody] CORREOSAREAMS nuevo)
|
||||||
{
|
{
|
||||||
|
ErrorModel _errorModel = new ErrorModel();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this._context.CORREOSAREAMS.Add(nuevo);
|
this._context.CORREOSAREAMS.Add(nuevo);
|
||||||
this._context.SaveChanges();
|
this._context.SaveChanges();
|
||||||
|
|
||||||
return Ok("Registro guardado correctamente.");
|
_errorModel.error = false;
|
||||||
|
_errorModel.cuerpo.Add("Registro guardado correctamente.");
|
||||||
|
return Ok(_errorModel);
|
||||||
|
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -49,7 +52,7 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
[HttpPatch]
|
[HttpPatch]
|
||||||
public IActionResult patch([FromBody] CORREOSAREAMS actualizar)
|
public IActionResult patch([FromBody] CORREOSAREAMS actualizar)
|
||||||
{
|
{
|
||||||
|
ErrorModel _errorModel = new ErrorModel();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CORREOSAREAMS? existente = this._context.CORREOSAREAMS.FirstOrDefault(c => c.NU_PK_CRRMS == actualizar.NU_PK_CRRMS);
|
CORREOSAREAMS? existente = this._context.CORREOSAREAMS.FirstOrDefault(c => c.NU_PK_CRRMS == actualizar.NU_PK_CRRMS);
|
||||||
@ -58,9 +61,12 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
this._context.Entry(existente).CurrentValues.SetValues(actualizar);
|
this._context.Entry(existente).CurrentValues.SetValues(actualizar);
|
||||||
this._context.SaveChanges();
|
this._context.SaveChanges();
|
||||||
|
|
||||||
return Ok("Registro guardado correctamente.");
|
_errorModel.error = false;
|
||||||
|
_errorModel.cuerpo.Add("Registro actualizado correctamente.");
|
||||||
|
return Ok(_errorModel);
|
||||||
|
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
using MSAdminUsuarios.Context;
|
using MSAdminUsuarios.Context;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MSAdminUsuarios.Dto;
|
||||||
|
using MSAdminUsuarios.Models;
|
||||||
|
|
||||||
namespace MSAdminUsuarios.Controllers
|
namespace MSAdminUsuarios.Controllers
|
||||||
{
|
{
|
||||||
@ -85,6 +88,116 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("PerfilPermisos")]
|
||||||
|
public async Task<IActionResult> PostPerfilPermisos(PerfilPermisosDTO nuevo)
|
||||||
|
{
|
||||||
|
ErrorModel _errorModel = new ErrorModel();
|
||||||
|
using (var transaccion = _context.Database.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (nuevo == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Sin datos a guardar.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaccion.CreateSavepoint("InicioCreacionPerfilPermisos");
|
||||||
|
|
||||||
|
if (nuevo.perfil == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Sin perfil a guardar.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nuevo.perfil.TX_UUID_PFL == null)
|
||||||
|
{
|
||||||
|
Guid uuid = Guid.NewGuid();
|
||||||
|
var UUID = uuid.ToString();
|
||||||
|
nuevo.perfil.TX_UUID_PFL = UUID;
|
||||||
|
|
||||||
|
_context.PERFILESMs.Add(nuevo.perfil);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PERFIL? existe = _context.PERFILESMs.FirstOrDefault(prfl => prfl.TX_UUID_PFL == nuevo.perfil.TX_UUID_PFL);
|
||||||
|
if (existe == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("El perfil no existe.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
existe.TX_PERFIL_PFL = nuevo.perfil.TX_PERFIL_PFL;
|
||||||
|
existe.NU_ROL_PFL = nuevo.perfil.NU_ROL_PFL;
|
||||||
|
existe.BL_ESTADO_PFL = nuevo.perfil.BL_ESTADO_PFL;
|
||||||
|
|
||||||
|
_context.PERFILESMs.Update(existe);
|
||||||
|
_context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Validacion agregada mientras se aclara el proceso
|
||||||
|
|
||||||
|
PERFIL? creado = await _context.PERFILESMs.FirstOrDefaultAsync(prfl => prfl.TX_UUID_PFL == nuevo.perfil.TX_UUID_PFL);
|
||||||
|
|
||||||
|
if (nuevo.permisos != null)
|
||||||
|
{
|
||||||
|
// Se cambia a estado 0 todos los perfiles por usuario existentes
|
||||||
|
List<PERMISO> permisos = _context.PERMISOSMs.Where(x => x.BL_ESTADO_PMS == 1 && x.NU_FK_PFL == creado.NU_PK_PFL).ToList();
|
||||||
|
|
||||||
|
foreach (var permiso in permisos)
|
||||||
|
{
|
||||||
|
permiso.BL_ESTADO_PMS = 0;
|
||||||
|
_context.PERMISOSMs.Update(permiso);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var pxp in nuevo.permisos)
|
||||||
|
{
|
||||||
|
PERMISO? existe = _context.PERMISOSMs.FirstOrDefault(pm => pm.NU_FK_PFL == pxp.NU_FK_PFL && pm.NU_FK_MS == pxp.NU_FK_MS);
|
||||||
|
|
||||||
|
if (existe != null)
|
||||||
|
{
|
||||||
|
//Si existe activamos estado 1 del perfil
|
||||||
|
existe.BL_ESTADO_PMS = 1;
|
||||||
|
_context.Update(existe);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pxp == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add($"Permiso sin valores");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pxp.BL_ESTADO_PMS = 1;
|
||||||
|
pxp.NU_FK_PFL = creado.NU_PK_PFL;
|
||||||
|
_context.PERMISOSMs.Add(pxp);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transaccion.Commit();
|
||||||
|
|
||||||
|
_errorModel.error = false;
|
||||||
|
_errorModel.cuerpo.Add("Perfil creado correctamente");
|
||||||
|
return Ok(_errorModel);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
transaccion.RollbackToSavepoint("InicioCreacionPerfilPermisos");
|
||||||
|
return BadRequest(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ using System.Threading.Channels;
|
|||||||
using MSAdminUsuarios.Dto.Externos.MsAgendaMedica;
|
using MSAdminUsuarios.Dto.Externos.MsAgendaMedica;
|
||||||
using static MSAdminUsuarios.Utils.RabbitMQService;
|
using static MSAdminUsuarios.Utils.RabbitMQService;
|
||||||
using MSAdminUsuarios.Utils;
|
using MSAdminUsuarios.Utils;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
|
|
||||||
namespace MSAdminUsuarios.Controllers
|
namespace MSAdminUsuarios.Controllers
|
||||||
{
|
{
|
||||||
@ -106,7 +107,8 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
|
|
||||||
consulta = (from dm in _context.USUARIOSMs
|
consulta = (from dm in _context.USUARIOSMs
|
||||||
where dm.NU_ESTADO_USUMS >= 0
|
where dm.NU_ESTADO_USUMS >= 0
|
||||||
select new UsuarioDTO(dm)).ToList();
|
orderby dm.NU_PK_USUMS
|
||||||
|
select new UsuarioDTO(dm)).ToList();
|
||||||
|
|
||||||
return Ok(consulta);
|
return Ok(consulta);
|
||||||
}
|
}
|
||||||
@ -203,6 +205,10 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
var ult = _context.USUARIOSMs.Max(x => x.NU_PK_USUMS) + 1;
|
var ult = _context.USUARIOSMs.Max(x => x.NU_PK_USUMS) + 1;
|
||||||
usuario.TX_PKDOC_USUMS = ult.ToString();
|
usuario.TX_PKDOC_USUMS = ult.ToString();
|
||||||
}
|
}
|
||||||
|
if(usuario.TX_PASSWORD_USUMS == null)
|
||||||
|
{
|
||||||
|
usuario.TX_PASSWORD_USUMS = usuario.TX_PKDOC_USUMS;
|
||||||
|
}
|
||||||
|
|
||||||
if (usuario.TX_PASSWORD_USUMS != null)
|
if (usuario.TX_PASSWORD_USUMS != null)
|
||||||
{
|
{
|
||||||
@ -214,7 +220,13 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
Guid uuid = Guid.NewGuid();
|
Guid uuid = Guid.NewGuid();
|
||||||
var UUID = uuid.ToString();
|
var UUID = uuid.ToString();
|
||||||
usuario.TX_UUID_USUMS = UUID;
|
usuario.TX_UUID_USUMS = UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Validacion agregada mientras se aclara el proceso
|
||||||
|
if (usuario.TX_SEDES_USUMS == null || usuario.TX_SEDES_USUMS.Length == 0)
|
||||||
|
{
|
||||||
|
usuario.TX_SEDES_USUMS = "[0]";
|
||||||
|
}
|
||||||
|
|
||||||
_context.USUARIOSMs.Add(usuario);
|
_context.USUARIOSMs.Add(usuario);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
@ -529,6 +541,186 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("UsuarioPerfiles")]
|
||||||
|
public async Task<IActionResult> PostUsuarioPerfiles(UsuarioPerfilesDTO nuevo)
|
||||||
|
{
|
||||||
|
ErrorModel _errorModel = new ErrorModel();
|
||||||
|
using (var transaccion = _context.Database.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (nuevo == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Sin datos a guardar.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaccion.CreateSavepoint("InicioCreacionUsuarioPerfiles");
|
||||||
|
|
||||||
|
if (nuevo.usuario == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Sin usuario a guardar.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nuevo.usuario.TX_CORREO_USUMS == null && nuevo.usuario.TX_LOGINNAME_USUMS == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Indique algún correo.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nuevo.usuario.TX_UUID_USUMS == null)
|
||||||
|
{
|
||||||
|
Guid uuid = Guid.NewGuid();
|
||||||
|
var UUID = uuid.ToString();
|
||||||
|
nuevo.usuario.TX_UUID_USUMS = UUID;
|
||||||
|
|
||||||
|
if (nuevo.usuario.TX_PASSWORD_USUMS == null)
|
||||||
|
{
|
||||||
|
nuevo.usuario.TX_PASSWORD_USUMS = nuevo.usuario.TX_PKDOC_USUMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nuevo.usuario.TX_PASSWORD_USUMS != null)
|
||||||
|
{
|
||||||
|
nuevo.usuario.TX_PASSWORD_USUMS = _encript.EncryptPwd(nuevo.usuario.TX_PASSWORD_USUMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nuevo.usuario.TX_SEDES_USUMS == null || nuevo.usuario.TX_SEDES_USUMS.Length == 0)
|
||||||
|
{
|
||||||
|
nuevo.usuario.TX_SEDES_USUMS = "[0]";
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.USUARIOSMs.Add(nuevo.usuario);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USUARIO? existe = _context.USUARIOSMs.FirstOrDefault(usu => usu.TX_UUID_USUMS == nuevo.usuario.TX_UUID_USUMS);
|
||||||
|
if (existe == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add("Sin usuario no existe.");
|
||||||
|
return Conflict(_errorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
existe.NU_TIPODOC_USUMS = nuevo.usuario.NU_TIPODOC_USUMS;
|
||||||
|
existe.TX_PRIMERNOM_USUMS = nuevo.usuario.TX_PRIMERNOM_USUMS;
|
||||||
|
existe.TX_SEGUNDONOM_USUMS = nuevo.usuario.TX_SEGUNDONOM_USUMS;
|
||||||
|
existe.TX_PRIMERAPELL_USUMS = nuevo.usuario.TX_PRIMERAPELL_USUMS;
|
||||||
|
existe.TX_SEGUNDOAPELL_USUMS = nuevo.usuario.TX_SEGUNDOAPELL_USUMS;
|
||||||
|
existe.TX_CELULAR_USUMS = nuevo.usuario.TX_CELULAR_USUMS;
|
||||||
|
existe.TX_TELEFONO_USUMS = nuevo.usuario.TX_TELEFONO_USUMS;
|
||||||
|
existe.TX_CORREO_USUMS = nuevo.usuario.TX_CORREO_USUMS;
|
||||||
|
existe.TX_DIRECCION_USUMS = nuevo.usuario.TX_DIRECCION_USUMS;
|
||||||
|
existe.BL_PERTENCEIPS_USUMS = nuevo.usuario.BL_PERTENCEIPS_USUMS;
|
||||||
|
existe.TX_NOMBRE_PVD = nuevo.usuario.TX_NOMBRE_PVD;
|
||||||
|
existe.BL_VIENELDAP_USUMS = nuevo.usuario.BL_VIENELDAP_USUMS;
|
||||||
|
existe.NU_GRUPO_USUMS = nuevo.usuario.NU_GRUPO_USUMS;
|
||||||
|
existe.NU_CARGO_USUMS = nuevo.usuario.NU_CARGO_USUMS;
|
||||||
|
existe.NU_MODALIDADCTT_USUMS = nuevo.usuario.NU_MODALIDADCTT_USUMS;
|
||||||
|
existe.TX_SEDES_USUMS = nuevo.usuario.TX_SEDES_USUMS;
|
||||||
|
existe.NU_BLOQUEO_USUMS = nuevo.usuario.NU_BLOQUEO_USUMS;
|
||||||
|
existe.NU_TIPOUSUARIO_USUMS = nuevo.usuario.NU_TIPOUSUARIO_USUMS;
|
||||||
|
existe.TX_REGPROF_MDC = nuevo.usuario.TX_REGPROF_MDC;
|
||||||
|
|
||||||
|
if (existe.TX_PASSWORD_USUMS == null || existe.TX_PASSWORD_USUMS == "")
|
||||||
|
{
|
||||||
|
existe.TX_PASSWORD_USUMS = _encript.EncryptPwd(nuevo.usuario.TX_PKDOC_USUMS!);
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.USUARIOSMs.Update(existe);
|
||||||
|
_context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Validacion agregada mientras se aclara el proceso
|
||||||
|
|
||||||
|
USUARIO? creado = await _context.USUARIOSMs.FirstOrDefaultAsync(us => us.TX_UUID_USUMS == nuevo.usuario.TX_UUID_USUMS);
|
||||||
|
|
||||||
|
if (nuevo.perfiles != null)
|
||||||
|
{
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
// Se cambia a estado 0 todos los perfiles por usuario existentes
|
||||||
|
var existe_plfxusu = _context.PERFILESPORUSUARIOs.Where(x => x.BL_ESTADO_PFLXUSU == 1 && x.TX_UUID_USUMS == nuevo.usuario.TX_UUID_USUMS).ToList();
|
||||||
|
|
||||||
|
foreach (var cu in existe_plfxusu)
|
||||||
|
{
|
||||||
|
cu.BL_ESTADO_PFLXUSU = 0;
|
||||||
|
}
|
||||||
|
_context.PERFILESPORUSUARIOs.UpdateRange(existe_plfxusu);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
foreach (var pxu in nuevo.perfiles)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
//Se comprueba existencia de cada pxu en base de datos
|
||||||
|
/*var existe_pxu = (from dm in _context.PERFILESPORUSUARIOs
|
||||||
|
where dm.TX_UUID_PFL == pxu.TX_UUID_PFL
|
||||||
|
&& dm.TX_UUID_USUMS == pxu.TX_UUID_USUMS
|
||||||
|
select dm).ToList();*/
|
||||||
|
PERFILPORUSUARIO? existe = _context.PERFILESPORUSUARIOs.FirstOrDefault(pu => pu.TX_UUID_PFL == pxu.TX_UUID_PFL && pu.TX_UUID_USUMS == pxu.TX_UUID_USUMS);
|
||||||
|
|
||||||
|
if (existe != null)
|
||||||
|
{
|
||||||
|
//Si existe activamos estado 1 del perfil
|
||||||
|
existe.BL_ESTADO_PFLXUSU = 1;
|
||||||
|
_context.Update(existe);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pxu == null)
|
||||||
|
{
|
||||||
|
_errorModel.error = true;
|
||||||
|
_errorModel.cuerpo.Add($"Perfil por usuario #{count} sin valores");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pxu.BL_ESTADO_PFLXUSU = 1;
|
||||||
|
pxu.TX_UUID_USUMS = nuevo.usuario.TX_UUID_USUMS;
|
||||||
|
_context.PERFILESPORUSUARIOs.Add(pxu);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> all = new List<string>();
|
||||||
|
|
||||||
|
all.Add($"Total registros: {nuevo.perfiles.Count().ToString()}");
|
||||||
|
all.Add($"Exitosos: {(nuevo.perfiles.Count() - _errorModel.cuerpo.Count()).ToString()}");
|
||||||
|
all.Add($"Erroneos: {_errorModel.cuerpo.Count().ToString()}");
|
||||||
|
|
||||||
|
var flag_r = 0;
|
||||||
|
foreach (var r in _errorModel.cuerpo)
|
||||||
|
{
|
||||||
|
flag_r++;
|
||||||
|
all.Add($"Error #{flag_r}: {r}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_errorModel.cuerpo.Count() > 0)
|
||||||
|
{
|
||||||
|
return Conflict(all.ToList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transaccion.Commit();
|
||||||
|
|
||||||
|
_errorModel.error = false;
|
||||||
|
_errorModel.cuerpo.Add("Usuario creado correctamente");
|
||||||
|
return Ok(_errorModel);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
transaccion.RollbackToSavepoint("InicioCreacionUsuarioPerfiles");
|
||||||
|
return BadRequest(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
Microservicios/MsUsuarios/Dto/PerfilPermisosDTO.cs
Normal file
10
Microservicios/MsUsuarios/Dto/PerfilPermisosDTO.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using MSAdminUsuarios.Context;
|
||||||
|
|
||||||
|
namespace MSAdminUsuarios.Dto
|
||||||
|
{
|
||||||
|
public class PerfilPermisosDTO
|
||||||
|
{
|
||||||
|
public PERFIL? perfil { get; set; }
|
||||||
|
public PERMISO[]? permisos { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ namespace MSAdminUsuarios.Dto
|
|||||||
public string? TX_CELULAR_USUMS { get; set; }
|
public string? TX_CELULAR_USUMS { get; set; }
|
||||||
public string? TX_CORREO_USUMS { get; set; }
|
public string? TX_CORREO_USUMS { get; set; }
|
||||||
public int? NU_ESTADO_USUMS { get; set; }
|
public int? NU_ESTADO_USUMS { get; set; }
|
||||||
public string? TX_PASSWORD_USUMS { get; set; }
|
//public string? TX_PASSWORD_USUMS { get; set; }
|
||||||
public int? NU_TIPODOC_USUMS { get; set; }
|
public int? NU_TIPODOC_USUMS { get; set; }
|
||||||
public int? NU_PK_USUMS { get; set; }
|
public int? NU_PK_USUMS { get; set; }
|
||||||
public int? BL_PERTENCEIPS_USUMS { get; set; }
|
public int? BL_PERTENCEIPS_USUMS { get; set; }
|
||||||
|
10
Microservicios/MsUsuarios/Dto/UsuarioPerfilesDTO.cs
Normal file
10
Microservicios/MsUsuarios/Dto/UsuarioPerfilesDTO.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using MSAdminUsuarios.Context;
|
||||||
|
|
||||||
|
namespace MSAdminUsuarios.Dto
|
||||||
|
{
|
||||||
|
public class UsuarioPerfilesDTO
|
||||||
|
{
|
||||||
|
public USUARIO? usuario { get; set; }
|
||||||
|
public PERFILPORUSUARIO[]? perfiles { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user