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)
|
||||
{
|
||||
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
|
||||
{
|
||||
//
|
||||
//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();
|
||||
|
||||
@ -81,68 +122,69 @@ namespace MSAdminUsuarios.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[NonAction]
|
||||
public async Task<List<string>> GuardarPerfiles(PERFILPORUSUARIO[] guardar, ModelContext context)
|
||||
{
|
||||
//using var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60));
|
||||
try
|
||||
{
|
||||
List<string> error = new(); //Inicializamos variable para guardar errores
|
||||
var count = 0;
|
||||
// Eliminado 19/03/23, RabbitMQ lo controla
|
||||
//[ApiExplorerSettings(IgnoreApi = true)]
|
||||
//[NonAction]
|
||||
//public async Task<List<string>> GuardarPerfiles(PERFILPORUSUARIO[] guardar, ModelContext context)
|
||||
//{
|
||||
// //using var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60));
|
||||
// try
|
||||
// {
|
||||
// List<string> error = new(); //Inicializamos variable para guardar errores
|
||||
// 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();
|
||||
// // 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 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();
|
||||
// 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;
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
//transactionScope.Complete();
|
||||
return error;
|
||||
// pxu.BL_ESTADO_PFLXUSU = 1;
|
||||
// context.PERFILESPORUSUARIOs.Add(pxu);
|
||||
// await context.SaveChangesAsync();
|
||||
// }
|
||||
// }
|
||||
// //transactionScope.Complete();
|
||||
// return error;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//transactionScope.Dispose();
|
||||
throw;
|
||||
}
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// //transactionScope.Dispose();
|
||||
// throw;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user