public ActionResult GetListId(int id)
        {
            UsuarioList UL = new UsuarioList();

            try
            {
                List <Rol> R   = Context.Rol.ToList();
                Usuario    Usr = Context.Usuario.Where(x => x.Id == id).FirstOrDefault();
                UL = new UsuarioList()
                {
                    Id            = Usr.Id,
                    Nombre        = Usr.Nombre,
                    Apellido      = Usr.Apellido,
                    Correo        = Usr.Correo,
                    Rol           = R?.Where(x => x.Id == Usr.Rol_Id).Select(x => x.RolName).FirstOrDefault(),
                    NombreUsuario = Usr.Nombre,
                    Estado        = Usr.Estado == false ? "Inactivo" : "Activo"
                };
                return(Ok(UL));
            }
            catch (Exception ex)
            {
                return(BadRequest("Error al obtener el usuario, error: " + ex.Message.ToString()));
            }
        }
        public ActionResult GetList()
        {
            UsuarioList        UL    = new UsuarioList();
            List <UsuarioList> LstUL = new List <UsuarioList>();

            try
            {
                List <Rol>     R   = Context.Rol.ToList();
                List <Usuario> Usr = Context.Usuario.ToList();

                if (Usr.Count > 0)
                {
                    foreach (Usuario U in Usr)
                    {
                        UL = new UsuarioList()
                        {
                            Id            = U.Id,
                            Nombre        = U.Nombre,
                            Apellido      = U.Apellido,
                            Correo        = U.Correo,
                            Rol           = R?.Where(x => x.Id == U.Rol_Id).Select(x => x.RolName).FirstOrDefault(),
                            NombreUsuario = U.Nombre,
                            Estado        = U.Estado == false ? "Inactivo" : "Activo"
                        };
                        LstUL.Add(UL);
                    }
                }
                return(Ok(LstUL));
            }
            catch (Exception ex)
            {
                return(BadRequest("Error al obtener el listado de Usuarios, error: " + ex.Message.ToString()));
            }
        }
Exemple #3
0
        public static UsuarioList Get()
        {
            UsuarioList res = new UsuarioList();

            SqlCommand    cmd = null;
            SqlDataReader dr  = null;

            string query = "SELECT * FROM Usuario";

            try
            {
                cmd = Methods.CreateBasicCommand(query);
                dr  = Methods.ExecuteDataReaderCommand(cmd);

                while (dr.Read())
                {
                    int     idUsuario = dr.GetInt32(0);
                    Usuario usuario   = UsuarioDal.Get(idUsuario);

                    res.Add(new Usuario()
                    {
                        UsuarioId         = idUsuario,
                        Nombre            = usuario.Nombre,
                        Apellido          = usuario.Apellido,
                        SexoId            = usuario.SexoId,
                        FechaNacimiento   = usuario.FechaNacimiento,
                        CorreoElectronico = usuario.CorreoElectronico,
                        Username          = usuario.Username,
                        Eliminado         = usuario.Eliminado,
                        Fechaderegistro   = usuario.Fechaderegistro,
                    });
                }
            }
            catch (SqlException ex)
            {
                //Methods.GenerateLogsRelease("KeyValuePacienteListDal", "Obtener", ex.Message + " " + ex.StackTrace);
                throw ex;
            }
            catch (Exception ex)
            {
                //Methods.GenerateLogsRelease("KeyValuePacienteListDal", "Obtener", ex.Message + " " + ex.StackTrace);
                throw ex;
            }
            finally
            {
                cmd.Connection.Close();
            }
            return(res);
        }
        /// <summary>
        /// Obtiene la lista de videojuegos
        /// </summary>
        /// <returns>Categoria Lista</returns>
        public static UsuarioList Get()
        {
            UsuarioList lista = null;

            try
            {
                lista = UsuarioListDal.Get();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lista);
        }
Exemple #5
0
        public dynamic Index(int?id)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "En Proceso"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Finalizado"
            });
            #endregion
            ProyectoIndex      PI    = new ProyectoIndex();
            UsuarioList        UL    = new UsuarioList();
            List <UsuarioList> LstUL = new List <UsuarioList>();
            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response = new Response();
                Rol            R = DB.Rol.Where(y => y.Rol1.ToUpper().Equals("OPERARIO")).FirstOrDefault();
                List <Usuario> U = DB.Usuario.Where(x => x.Rol_Id == R.Id && x.Estado == true).ToList();
                Proyecto       P = id != null?DB.Proyecto.Where(x => x.Id == id).FirstOrDefault() : null;

                if (U != null)
                {
                    foreach (Usuario usr in U)
                    {
                        UL = new UsuarioList()
                        {
                            Id       = usr.Id,
                            Nombre   = usr.Nombre,
                            Apellido = usr.Apellido,
                            Correo   = usr.Correo,
                            Usuario  = usr.Usuario1,
                        };
                        LstUL.Add(UL);
                    }
                }
                PI = new ProyectoIndex()
                {
                    Id          = P != null ? P.Id : 0,
                    Nombre      = P != null ? P.Nombre : "",
                    Descripcion = P != null ? P.Descripcion : "",
                    FechaInicio = P != null ? P.Fecha_Inicio : DateTime.Now,
                    FechaFin    = P != null ? P.Fecha_Fin : DateTime.Now,
                    Estado      = P != null ? P.Estado == false ? 0 : 1 : 0,
                    LstEstado   = LstEL
                };
                response.Successfully = true;
                response.Code         = 200;
                response.Message      = "Consulta realizada con éxito.";
                response.Result       = PI;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }
Exemple #6
0
        public dynamic List(int?id)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "Inactivo"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Activo"
            });
            #endregion
            UsuarioList        UL    = new UsuarioList();
            List <UsuarioList> LstUL = new List <UsuarioList>();
            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response = new Response();
                List <Rol>     R   = DB.Rol.ToList();
                List <Usuario> Usr = id == null?DB.Usuario.ToList() : DB.Usuario.Where(x => x.Id == id).ToList();

                if (Usr.Count > 0)
                {
                    foreach (Usuario U in Usr)
                    {
                        UL = new UsuarioList()
                        {
                            Id       = U.Id,
                            Nombre   = U.Nombre,
                            Apellido = U.Apellido,
                            Correo   = U.Correo,
                            Rol_Id   = U.Rol_Id,
                            Rol      = R?.Where(x => x.Id == U.Rol_Id).Select(x => x.Rol1).FirstOrDefault(),
                            Usuario  = U.Usuario1,
                            Estado   = U.Estado == false ? "Inactivo" : "Activo"
                        };
                        LstUL.Add(UL);
                    }
                    response.Message = "";
                    response.Result  = LstUL;
                }
                else
                {
                    response.Message = "No se encontro ningun Usuario";
                    response.Result  = null;
                }
                response.Successfully = true;
                response.Code         = 200;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }