public ActionResult Ver_Asignacion(int?id)
        {
            Modelo_Asignacion ma = new Modelo_Asignacion();
            Modelo_Bienes     mb = new Modelo_Bienes();
            Bienes            bie;
            Modelo_Personal   mp = new Modelo_Personal();
            Personal          per;

            if (id != null)
            {
                v_asi = ma.obtener(id);
                bie   = mb.obtener(v_asi.Id_bienes);
                per   = mp.obtener(v_asi.Id_personal);

                Info datos = new Info();
                datos.Obj_asi = v_asi;
                datos.Obj_bie = bie;
                datos.Obj_per = per;

                return(View(datos));
            }
            else
            {
                return(RedirectToAction("Consultar_Asignacion"));
            }

            //return View();
        }
        public ActionResult Ver_Encontrado(int?id)
        {
            Modelo_Encontrado me = new Modelo_Encontrado();
            Modelo_Bienes     mb = new Modelo_Bienes();
            Bienes            bie;

            if (id != null)
            {
                v_enc = me.obtener(id);
                bie   = mb.obtener(v_enc.Id_bienes);
                Info datos = new Info();
                datos.Obj_enc = v_enc;
                datos.Obj_bie = bie;
                ////arr = v_enc.arr_byte;
                //Image imagen;

                //MemoryStream ms = new MemoryStream(v_enc.arr_byte);

                //    imagen = Image.FromStream(ms);

                //ms = new MemoryStream();
                //imagen.Save(ms, ImageFormat.Jpeg);
                //ms.Position = 0;


                //return File(ms,"image/jpg");

                return(View(datos));
            }
            else
            {
                return(RedirectToAction("Consultar_Encontrado"));
            }
        }
        public ActionResult Consultar_Bienes()
        {
            Modelo_Bienes mb  = new Modelo_Bienes();
            List <Bienes> bie = new List <Bienes>();

            bie = mb.listar();

            if (bie == null)
            {
                return(Json(new { message = "Error al tratar de consultar los bienes", success = false, datos = bie }));
            }
            else
            {
                return(Json(new { message = "Se consiguió hacer la consulta", success = true, datos = bie }));
            }
        }
        public ActionResult eliminar(int id)
        {
            Modelo_Bienes mb = new Modelo_Bienes();

            if (mb.eliminar(id))
            {
                TempData["Eliminar"] = "Se eliminó Correctamente el Registro";
            }
            else
            {
                TempData["Eliminar"] = "No se eliminó Correctamente el Registro";
            }

            return(RedirectToAction("Consultar_Bien"));

            //return View();
        }
        public ActionResult Consultar_Bien(string nombre, string codigo, int id_categoria)
        {
            Modelo_Categoria mc = new Modelo_Categoria();
            List <Categoria> cat;
            List <Bienes>    bie;
            Modelo_Bienes    mb = new Modelo_Bienes();

            Info datos = new Info();

            bie = mb.buscar(nombre, codigo, id_categoria);
            cat = mc.listar();

            datos.Bie = bie;
            datos.Cat = cat;

            return(View(datos));
        }
        public ActionResult Modificar_Bien(int?id)
        {
            Modelo_Bienes    mb = new Modelo_Bienes();
            Modelo_Categoria mc = new Modelo_Categoria();
            List <Categoria> cat;

            if (id != null)
            {
                v_bie = mb.obtener(id);
                cat   = mc.listar();
                Info datos = new Info();
                datos.Obj_bie = v_bie;
                datos.Cat     = cat;

                return(View(datos));
            }
            else
            {
                return(RedirectToAction("Consultar_Bien"));
            }

            //return View();
        }
        public ActionResult Consultar_Bien()
        {
            Modelo_Categoria  mc = new Modelo_Categoria();
            Modelo_Inventario mi = new Modelo_Inventario();
            List <Categoria>  cat;
            List <Bienes>     bie;
            List <Inventario> inv;
            Modelo_Bienes     mb = new Modelo_Bienes();

            Info datos = new Info();

            bie = mb.listar();
            cat = mc.listar();
            inv = mi.listar();

            ViewBag.eliminar = TempData["Eliminar"];

            datos.Bie = bie;
            datos.Cat = cat;
            datos.Inv = inv;

            return(View(datos));
        }
        //[HttpPost]
        //public ActionResult Modificar_Asignacion(int id, string nombre, string password, string documento, string n_documento, string correo, string celular, string direccion, string cargo)
        //{
        //    Metodo_Usuario mu = new Metodo_Usuario();
        //    Usuario usu = new Usuario();
        //    string message;
        //    SortedList<string, string> error = new SortedList<string, string>();

        //    if (id != 0)
        //    {
        //        if (String.IsNullOrEmpty(nombre))
        //        {
        //            error.Add("sp_nombre", "Ingrese el nombre del Usuario");
        //        }
        //        if (String.IsNullOrEmpty(password))
        //        {
        //            error.Add("sp_password", "Ingrese el Password");
        //        }
        //        if (String.IsNullOrEmpty(documento))
        //        {
        //            error.Add("sp_documento", "Selecciones el tipo de Documento");
        //        }
        //        if (String.IsNullOrEmpty(n_documento))
        //        {
        //            error.Add("sp_n_documento", "Ingrese el N° del documento");
        //        }
        //        if (String.IsNullOrEmpty(correo))
        //        {
        //            error.Add("sp_correo", "Ingrese el correo del usuario");
        //        }
        //        if (String.IsNullOrEmpty(direccion))
        //        {
        //            error.Add("sp_direccion", "Ingrese la direccion del usuario");
        //        }
        //        if (String.IsNullOrEmpty(cargo))
        //        {
        //            error.Add("sp_cargo", "Ingrese el cargo del usuario");
        //        }

        //        if (error.Count == 0)
        //        {
        //            usu.Id_usuario = id;
        //            usu.Nombre = nombre == null ? "" : nombre;
        //            usu.Contrasena = password == null ? "" : password;
        //            usu.Documento = documento == null ? "" : documento;
        //            usu.N_documento = n_documento == null ? "" : n_documento;
        //            usu.Correo = correo == null ? "" : correo;
        //            usu.Celular = celular == null ? "" : celular;
        //            usu.Direccion = direccion == null ? "" : direccion;
        //            usu.Cargo = cargo == null ? "" : cargo;

        //            if (mu.actualizar(usu))
        //            {
        //                message = "Se actualizaron los datos correctamente";
        //            }
        //            else
        //            {
        //                message = "No se logró actualizar lo datos";
        //            }

        //            return Json(new { message = message, success = true });
        //        }
        //        else
        //        {
        //            message = "Ingrese los datos necesarios";
        //            return Json(new { message = message, success = false, datos = error });
        //        }
        //    }

        //    return RedirectToAction("Consultar_Asignacion");

        //}

        public ActionResult Registrar_Asignacion()
        {
            List <Gerencia> ger;
            List <Area>     are;
            List <Personal> per;
            List <Bienes>   bie;
            Metodo_Gerencia mg   = new Metodo_Gerencia();
            Modelo_Area     ma   = new Modelo_Area();
            Modelo_Personal mp   = new Modelo_Personal();
            Modelo_Bienes   mb   = new Modelo_Bienes();
            Info            dato = new Info();

            ger = mg.listar();
            are = ma.listar();
            per = mp.listar();
            bie = mb.listar();

            dato.Ger = ger;
            dato.Are = are;
            dato.Per = per;
            dato.Bie = bie;

            return(View(dato));
        }
        public ActionResult Registrar_Bien(int id_categoria, string nombre, string serie, string descripcion, string codigo, double precio, string estado, DateTime?fecha_ing, string marca, string color, string modelo, int alto, int ancho, int profundidad)
        {
            Bienes        bie = new Bienes();
            Modelo_Bienes mb  = new Modelo_Bienes();

            string message;
            string imagen = "";
            SortedList <string, string> error = new SortedList <string, string>();

            if (id_categoria == 0)
            {
                error.Add("sp_id_categoria", "Seleccione la categoria");
            }
            if (String.IsNullOrEmpty(nombre))
            {
                error.Add("sp_nombre", "Ingrese el nombre");
            }
            if (String.IsNullOrEmpty(serie))
            {
                error.Add("sp_nombre", "Ingrese el nombre");
            }
            if (String.IsNullOrEmpty(descripcion))
            {
                error.Add("sp_descripcion", "Ingrese su descripción");
            }
            if (String.IsNullOrEmpty(codigo))
            {
                error.Add("sp_codigo", "Ingrese el Codigo del bien");
            }
            if (precio == 0)
            {
                error.Add("sp_precio", "Ingrese el Valor del bien");
            }
            if (String.IsNullOrEmpty(estado))
            {
                error.Add("sp_estado", "Ingrese el estado del bien");
            }
            if (fecha_ing == null)
            {
                error.Add("sp_fecha_ing", "Ingrese la fecha");
            }
            if (String.IsNullOrEmpty(marca))
            {
                error.Add("sp_marca", "Ingrese la Marca");
            }
            if (String.IsNullOrEmpty(color))
            {
                error.Add("sp_color", "Ingrese el color del bien");
            }
            if (String.IsNullOrEmpty(modelo))
            {
                error.Add("sp_modelo", "Ingrese el modelo");
            }
            if (alto == 0)
            {
                error.Add("sp_alto", "Ingrese el alto");
            }
            if (ancho == 0)
            {
                error.Add("sp_anchor", "Ingrese el ancho");
            }
            if (profundidad == 0)
            {
                error.Add("sp_profundidad", "Ingrese la Profundidad");
            }

            if (error.Count == 0)
            {
                bie.Id_categoria = id_categoria == 0 ? 0 : id_categoria;;
                bie.Nombre       = nombre == null ? "" : nombre;
                bie.Serie        = serie == null ? "" : serie;
                bie.Descripcion  = descripcion == null ? "" : descripcion;
                bie.Codigo       = codigo == null ? "" : codigo;
                bie.Precio       = precio == 0 ? 0 : precio;
                bie.Estado       = estado == null ? "" : estado;
                bie.Fecha_ing    = fecha_ing == null ? DateTime.Now : fecha_ing.Value;
                bie.Marca        = marca == null ? "" : marca;
                bie.Color        = color == null ? "" : color;
                bie.Modelo       = modelo == null ? "" : modelo;
                bie.Alto         = alto == 0 ? 0 : alto;
                bie.Ancho        = ancho == 0 ? 0 : ancho;
                bie.Profundidad  = profundidad == 0 ? 0 : profundidad;
                bie.Imagen       = imagen == null ? "" : imagen;

                if (mb.guardar(bie))
                {
                    message = "Se guardaron los datos correctamente";
                }
                else
                {
                    message = "No se Guardaron lo datos";
                }

                return(Json(new { message = message, success = true }));
            }
            else
            {
                message = "Ingrese los datos necesarios";
                return(Json(new { message = message, success = false, datos = error }));
            }
        }