Revert PPU / independiente
This commit is contained in:
parent
aa8895ddc9
commit
5a90064d73
@ -45,12 +45,53 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
public async Task<IActionResult> GuardarPerfilesPorUsuario(PERFILPORUSUARIO[] guardar)
|
public async Task<IActionResult> GuardarPerfilesPorUsuario(PERFILPORUSUARIO[] guardar)
|
||||||
{
|
{
|
||||||
using var dbContextTransaction = _context.Database.BeginTransaction();
|
using var dbContextTransaction = _context.Database.BeginTransaction();
|
||||||
//List<string> error = new List<string>(); //Inicializamos variable para guardar errores
|
List<string> error = new(); //Inicializamos variable para guardar errores
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//var error = await GuardarPerfiles(guardar, _context);
|
||||||
|
|
||||||
var error = await GuardarPerfiles(guardar, _context);
|
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_FKDOC_USUMS == guardar[0].TX_FKDOC_USUMS).ToList();
|
||||||
|
|
||||||
|
foreach (var cu in existe_plfxusu)
|
||||||
|
{
|
||||||
|
cu.BL_ESTADO_PFLXUSU = 0;
|
||||||
|
_context.PERFILESPORUSUARIOs.Update(cu);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var pxu in guardar)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
//Se comprueba existencia de cada pxu en base de datos
|
||||||
|
var existe_pxu = (from dm in _context.PERFILESPORUSUARIOs
|
||||||
|
where dm.NU_FK_PFL == pxu.NU_FK_PFL
|
||||||
|
&& dm.TX_FKDOC_USUMS == pxu.TX_FKDOC_USUMS
|
||||||
|
select dm).ToList();
|
||||||
|
|
||||||
|
if (existe_pxu.Count() > 0)
|
||||||
|
{
|
||||||
|
//Si existe activamos estado 1 del perfil
|
||||||
|
existe_pxu[0].BL_ESTADO_PFLXUSU = 1;
|
||||||
|
_context.Update(existe_pxu[0]);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pxu == null)
|
||||||
|
{
|
||||||
|
error.Add($"Perfil por usuario #{count} sin valores");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pxu.BL_ESTADO_PFLXUSU = 1;
|
||||||
|
_context.PERFILESPORUSUARIOs.Add(pxu);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dbContextTransaction.Commit();
|
dbContextTransaction.Commit();
|
||||||
|
|
||||||
@ -81,68 +122,69 @@ namespace MSAdminUsuarios.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ApiExplorerSettings(IgnoreApi = true)]
|
// Eliminado 19/03/23, RabbitMQ lo controla
|
||||||
[NonAction]
|
//[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
public async Task<List<string>> GuardarPerfiles(PERFILPORUSUARIO[] guardar, ModelContext context)
|
//[NonAction]
|
||||||
{
|
//public async Task<List<string>> GuardarPerfiles(PERFILPORUSUARIO[] guardar, ModelContext context)
|
||||||
//using var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60));
|
//{
|
||||||
try
|
// //using var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60));
|
||||||
{
|
// try
|
||||||
List<string> error = new(); //Inicializamos variable para guardar errores
|
// {
|
||||||
var count = 0;
|
// List<string> error = new(); //Inicializamos variable para guardar errores
|
||||||
|
// var count = 0;
|
||||||
|
|
||||||
// Se cambia a estado 0 todos los perfiles por usuario existentes
|
// // 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_FKDOC_USUMS == guardar[0].TX_FKDOC_USUMS).ToList();
|
// var existe_plfxusu = context.PERFILESPORUSUARIOs.Where(x => x.BL_ESTADO_PFLXUSU == 1 && x.TX_FKDOC_USUMS == guardar[0].TX_FKDOC_USUMS).ToList();
|
||||||
|
|
||||||
foreach (var cu in existe_plfxusu)
|
// foreach (var cu in existe_plfxusu)
|
||||||
{
|
// {
|
||||||
cu.BL_ESTADO_PFLXUSU = 0;
|
// cu.BL_ESTADO_PFLXUSU = 0;
|
||||||
context.PERFILESPORUSUARIOs.Update(cu);
|
// context.PERFILESPORUSUARIOs.Update(cu);
|
||||||
await context.SaveChangesAsync();
|
// await context.SaveChangesAsync();
|
||||||
}
|
// }
|
||||||
|
|
||||||
foreach (var pxu in guardar)
|
// foreach (var pxu in guardar)
|
||||||
{
|
// {
|
||||||
count++;
|
// count++;
|
||||||
//Se comprueba existencia de cada pxu en base de datos
|
// //Se comprueba existencia de cada pxu en base de datos
|
||||||
var existe_pxu = (from dm in context.PERFILESPORUSUARIOs
|
// var existe_pxu = (from dm in context.PERFILESPORUSUARIOs
|
||||||
where dm.NU_FK_PFL == pxu.NU_FK_PFL
|
// where dm.NU_FK_PFL == pxu.NU_FK_PFL
|
||||||
&& dm.TX_FKDOC_USUMS == pxu.TX_FKDOC_USUMS
|
// && dm.TX_FKDOC_USUMS == pxu.TX_FKDOC_USUMS
|
||||||
select dm).ToList();
|
// select dm).ToList();
|
||||||
|
|
||||||
if (existe_pxu.Count() > 0)
|
// if (existe_pxu.Count() > 0)
|
||||||
{
|
// {
|
||||||
//Si existe activamos estado 1 del perfil
|
// //Si existe activamos estado 1 del perfil
|
||||||
existe_pxu[0].BL_ESTADO_PFLXUSU = 1;
|
// existe_pxu[0].BL_ESTADO_PFLXUSU = 1;
|
||||||
context.Update(existe_pxu[0]);
|
// context.Update(existe_pxu[0]);
|
||||||
await context.SaveChangesAsync();
|
// await context.SaveChangesAsync();
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
if (pxu == null)
|
// if (pxu == null)
|
||||||
{
|
// {
|
||||||
error.Add($"Perfil por usuario #{count} sin valores");
|
// error.Add($"Perfil por usuario #{count} sin valores");
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pxu.BL_ESTADO_PFLXUSU = 1;
|
// pxu.BL_ESTADO_PFLXUSU = 1;
|
||||||
context.PERFILESPORUSUARIOs.Add(pxu);
|
// context.PERFILESPORUSUARIOs.Add(pxu);
|
||||||
await context.SaveChangesAsync();
|
// await context.SaveChangesAsync();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//transactionScope.Complete();
|
// //transactionScope.Complete();
|
||||||
return error;
|
// return error;
|
||||||
|
|
||||||
}
|
// }
|
||||||
catch (Exception)
|
// catch (Exception)
|
||||||
{
|
// {
|
||||||
//transactionScope.Dispose();
|
// //transactionScope.Dispose();
|
||||||
throw;
|
// throw;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user