public async Task <RolFuncionModel> ObtenerRolYFunciones(int idRol) { RolFuncionModel rolFuncion = null; List <FuncionModel> funciones = new List <FuncionModel>(); FuncionModel funcionModel = null; try { Rol rolEntity = await _context.Rol.FirstOrDefaultAsync(a => a.IdRol == idRol); if (rolEntity != null) { //List<FuncionRol> funcionRolEntity = await _context.FuncionRol.Where(x => x.Rol == idRol).ToListAsync(); List <FuncionRol> aux = await _context.FuncionRol .Include(a => a.FuncionNavigation) .Include("FuncionNavigation") .Where(c => c.Rol == idRol).ToListAsync(); foreach (var funcion in aux) { funcionModel = new FuncionModel() { FuncionId = (int)funcion.FuncionNavigation.IdFuncion, FuncionNombre = funcion.FuncionNavigation.TipoFuncion, Descripcion = funcion.FuncionNavigation.Descripcion }; funciones.Add(funcionModel); } rolFuncion = new RolFuncionModel() { Funciones = funciones, IdRole = rolEntity.IdRol, DescriptionRole = rolEntity.Descripcion }; return(rolFuncion); } else { return(rolFuncion); } } catch (ArgumentException) { throw; } catch (Exception ex) { var e = ex.Message; throw; } }
public async Task <IActionResult> UsuarioPorId(int idUsuario) { UserData response = new UserData(); UsuarioModel usuario = await _usuarioRepository.DetalleUsuarioPorId(idUsuario); RolFuncionModel rolFunciones = null; if (usuario != null) { var idRol = usuario.Rol.GetValueOrDefault(); rolFunciones = await _usuarioRepository.ObtenerRolYFunciones(idRol); response.usuario = usuario; response.rolFunciones = rolFunciones; return(Ok(response)); } else { return(BadRequest(false)); } }