public IActionResult Edicao(Usuario u)
        {
            using (BibliotecaContext bc = new BibliotecaContext()) {
                Usuario usu = bc.Usuario.Find(u.Id);
                usu.Login = u.Login;
                usu.Senha = u.Senha;

                bc.SaveChanges();

                return(RedirectToAction("Listagem"));
            }
        }
예제 #2
0
 public static List <LibroDet> List2()
 {
     using (var ctx = new BibliotecaContext()) {
         List <LibroDet>     lld = new List <LibroDet>();
         IEnumerable <Libro> le  = ctx.Libros.OrderBy(l => l.Codigo);
         foreach (Libro l in le)
         {
             LibroDet ld = new LibroDet();
             if (l.Autor != null)
             {
                 ld.Autor = l.Autor.Apellidos + " " + l.Autor.Nombres;
             }
             else
             {
                 ld.Autor = "";
             }
             if (l.Clasificacion != null)
             {
                 ld.ClasifAbrev = l.Clasificacion.Abreviatura;
             }
             else
             {
                 ld.ClasifAbrev = "";
             }
             ld.Codigo = l.Codigo;
             if (l.Ejemplares != null)
             {
                 ld.Copias = l.Ejemplares.Count;
             }
             ld.Edicion = "";
             if (l.Edicion != null)
             {
                 ld.Edicion = l.Edicion;
             }
             if (l.Editorial != null)
             {
                 ld.Editorial = l.Editorial.Nombre;
             }
             else
             {
                 ld.Editorial = "";
             }
             ld.Estado      = l.Estado;
             ld.Id          = l.Id;
             ld.Idioma      = l.Idioma;
             ld.Observacion = l.Observacion;
             ld.Tipo        = l.Tipo;
             ld.Titulo      = l.Titulo;
             lld.Add(ld);
         }
         return(lld);
     }
 }
예제 #3
0
 public static void Create(Editorial editorial)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             editorial.Pais = ctx.Paises.Where(p => p.Id == editorial.Pais.Id).FirstOrDefault();
             ctx.Editoriales.AddObject(editorial);
             ctx.SaveChanges();
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #4
0
 public static void Create(Libro libro)
 {
     using (var ctx = new BibliotecaContext()) {
         if (ctx.Libros.Where(l => l.Codigo == libro.Codigo).Count() > 0)
         {
             throw new Excepcion("Ya existe un registro con el código '" + libro.Codigo + "'");
         }
         if (string.IsNullOrEmpty(libro.Edicion))
         {
             libro.Edicion = "";
         }
         if (string.IsNullOrEmpty(libro.Resumen))
         {
             libro.Resumen = "";
         }
         if (string.IsNullOrEmpty(libro.Observacion))
         {
             libro.Observacion = "";
         }
         if (string.IsNullOrEmpty(libro.ISBN))
         {
             libro.ISBN = "";
         }
         if (string.IsNullOrEmpty(libro.Idioma))
         {
             libro.Idioma = "";
         }
         List <Ejemplar> le = null;
         if (libro.Ejemplares != null)
         {
             le = libro.Ejemplares.ToList();
             validarEjemplares(ctx, le);
             libro.Ejemplares = null;
         }
         Autor         a1 = ctx.Autores.Where(a => a.Id == libro.Autor.Id).FirstOrDefault();
         Editorial     e1 = ctx.Editoriales.Include("Pais").Where(e => e.Id == libro.Editorial.Id).FirstOrDefault();
         Clasificacion c1 = ctx.Clasificaciones.Where(c => c.Id == libro.Clasificacion.Id).FirstOrDefault();
         libro.Autor         = null;
         libro.Clasificacion = null;
         libro.Editorial     = null;
         ctx.Libros.AddObject(libro);
         ctx.SaveChanges();
         libro.Autor         = a1;
         libro.Editorial     = e1;
         libro.Clasificacion = c1;
         foreach (Ejemplar ejemplar in le)
         {
             ejemplar.Libro = libro;
             ctx.Ejemplares.AddObject(ejemplar);
         }
         ctx.SaveChanges();
     }
 }
예제 #5
0
 private void txtLivro_TextChanged(object sender, EventArgs e)
 {
     gridEditoras.DataSource = null;
     using (var context = new BibliotecaContext())
     {
         var listaLivro = context
                          .Livros.Where(x => x.Titulo.Contains(txtLivro.Text))
                          .ToList <Livro>();
         gridEditoras.DataSource = listaLivro;
         gridEditoras.Columns["Editora"].Visible = false;
     }
 }
예제 #6
0
        public void Editar(Login editadoUsuario)
        {
            using (BibliotecaContext bd = new BibliotecaContext())
            {
                Login usuario = bd.Logins.Find(editadoUsuario.Id);

                usuario.Nome  = editadoUsuario.Nome;
                usuario.Senha = editadoUsuario.Senha;

                bd.SaveChanges();
            }
        }
예제 #7
0
        private void txtEditora_TextChanged(object sender, EventArgs e)
        {
            using (var context = new BibliotecaContext())
            {
                var listaEditoras = context
                    .Editoras.Where(x => x.Descricao.Contains(txtEditora.Text))
                    .ToList<Editora>();
                gridEditoras.DataSource = listaEditoras;
                gridEditoras.Columns["Livros"].Visible = false;

            }
        }
예제 #8
0
 public static int CambiarEstado(int EditorialId)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             Editorial e1 = ctx.Editoriales.Where(e => e.Id == EditorialId).FirstOrDefault();
             e1.Estado = (e1.Estado + 1) % 2;
             ctx.SaveChanges();
             return(e1.Estado);
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #9
0
 public static void devolver(int prestamoId)
 {
     using (var ctx = new BibliotecaContext())
     {
         Prestamo p = ctx.Prestamos.SingleOrDefault(b => b.PrestamoId == prestamoId);
         if (p != null)
         {
             p.devuelto            = true;
             p.fechaDevolucionReal = DateTime.Now;
             ctx.SaveChanges();
         }
     }
 }
예제 #10
0
        public static List <PrestamoViewModel> findNoDevueltos()
        {
            List <Prestamo> ps;

            using (var ctx = new BibliotecaContext())
            {
                ps = ctx.Prestamos.Where(b => b.devuelto == false).ToList();
            }
            List <PrestamoViewModel> pvms = mapper(ps);

            cargarDatos(pvms);
            return(pvms);
        }
예제 #11
0
        private void frmLivros_Load(object sender, EventArgs e)
        {
            using (var context = new BibliotecaContext())
            {
                //Expressão Lambra para ordenar a lista de editoras
                List <Editora> listaEditoras = context.Editoras.OrderBy(x => x.Descricao).ToList <Editora>();

                comboEditora.DataSource    = listaEditoras;
                comboEditora.DisplayMember = "Descricao";
                comboEditora.ValueMember   = "EditoraId";
                comboEditora.Invalidate();
            }
        }
예제 #12
0
 public static int CambiarEstado(int ClasificacionId)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             Clasificacion c1 = ctx.Clasificaciones.Where(c => c.Id == ClasificacionId).FirstOrDefault();
             c1.Estado = (c1.Estado + 1) % 2;
             ctx.SaveChanges();
             return(c1.Estado);
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #13
0
 public static int CambiarEstado(int AutorId)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             Autor a1 = ctx.Autores.Where(a => a.Id == AutorId).FirstOrDefault();
             a1.Estado = (a1.Estado + 1) % 2;
             ctx.SaveChanges();
             return(a1.Estado);
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #14
0
        public static List <LibroViewModel> findAll()
        {
            List <LibroViewModel> lvms;
            List <Libro>          l;

            using (var ctx = new BibliotecaContext())
            {
                l = ctx.Libros.ToList();
            }
            lvms = mapper(l);
            verificarSiTienenPrestamos(lvms);
            return(lvms);
        }
예제 #15
0
        public IActionResult Edicao(Usuario l)
        {
            using (BibliotecaContext bc = new BibliotecaContext())
            {
                Usuario user = bc.Usuarios.Find(l.Id);
                user.Login = l.Login;
                user.Senha = l.Senha;

                bc.SaveChanges();

                return(RedirectToAction("Listagem"));
            }
        }
예제 #16
0
        public static List <UsuarioViewModel> findAll()
        {
            List <UsuarioViewModel> uvms;
            List <Usuario>          ul;

            using (var ctx = new BibliotecaContext())
            {
                ul = ctx.Usuarios.ToList();
            }
            uvms = mapper(ul);
            verificarSiTienenPrestamos(uvms);
            return(uvms);
        }
예제 #17
0
        public static List <PrestamoViewModel> findAll()
        {
            List <Prestamo> ps;

            using (var ctx = new BibliotecaContext())
            {
                ps = ctx.Prestamos.ToList();
            }
            List <PrestamoViewModel> pvms = mapper(ps);

            cargarDatos(pvms);
            return(pvms);
        }
예제 #18
0
 public static void Update(Editorial editorial)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             Editorial e1 = ctx.Editoriales.Where(e => e.Id == editorial.Id).FirstOrDefault();
             e1.Estado = editorial.Estado;
             e1.Nombre = editorial.Nombre;
             e1.Pais   = ctx.Paises.Where(p => p.Id == editorial.Pais.Id).FirstOrDefault();
             ctx.SaveChanges();
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #19
0
 private static void validarEjemplares(BibliotecaContext ctx, List <Ejemplar> listaEjemplar)
 {
     foreach (Ejemplar ejemplar in listaEjemplar)
     {
         if (!string.IsNullOrEmpty(ejemplar.Codigo) && ctx.Ejemplares.Where(e => e.Id != ejemplar.Id && e.Codigo == ejemplar.Codigo).Count() > 0)
         {
             throw new Excepcion("Ya existe un ejemplar con código '" + ejemplar.Codigo + "'");
         }
         else if (string.IsNullOrEmpty(ejemplar.CodBarras))
         {
             ejemplar.CodBarras = "";
         }
     }
     foreach (Ejemplar ejemplar in listaEjemplar)
     {
         if (!string.IsNullOrEmpty(ejemplar.CodBarras) && ctx.Ejemplares.Where(e => e.Id != ejemplar.Id && e.CodBarras == ejemplar.CodBarras).Count() > 0)
         {
             throw new Excepcion("Ya existe un ejemplar con el código de barras '" + ejemplar.CodBarras + "'");
         }
         else if (string.IsNullOrEmpty(ejemplar.CodBarras))
         {
             ejemplar.CodBarras = "";
         }
     }
     foreach (Ejemplar ejemplar in listaEjemplar)
     {
         if (!string.IsNullOrEmpty(ejemplar.CodRFID) && ctx.Ejemplares.Where(e => e.Id != ejemplar.Id && e.CodRFID == ejemplar.CodRFID).Count() > 0)
         {
             throw new Excepcion("Ya existe un ejemplar con el código RFID '" + ejemplar.CodRFID + "'");
         }
         else if (string.IsNullOrEmpty(ejemplar.CodRFID))
         {
             ejemplar.CodRFID = "";
         }
     }
     foreach (Ejemplar ejemplar in listaEjemplar)
     {
         if (string.IsNullOrEmpty(ejemplar.Codigo))
         {
             ejemplar.Codigo = "";
         }
     }
     foreach (Ejemplar ejemplar in listaEjemplar)
     {
         if (string.IsNullOrEmpty(ejemplar.Ubicacion))
         {
             ejemplar.Ubicacion = "";
         }
     }
 }
예제 #20
0
 public static void Delete(int LibroId)
 {
     using (var ctx = new BibliotecaContext()) {
         IEnumerable <Ejemplar> le = ctx.Ejemplares.Where(e => e.Libro.Id == LibroId);
         //if(ctx.Prestamos.Where(p => p.Ejemplares.Intersect(le).Count() > 0).FirstOrDefault() != null)
         //    throw new Excepcion("No se puede eliminar el registro, tiene participación en alguna transacción");
         foreach (Ejemplar e in le)
         {
             ctx.Ejemplares.DeleteObject(e);
         }
         ctx.Libros.DeleteObject(ctx.Libros.Where(l => l.Id == LibroId).FirstOrDefault());
         ctx.SaveChanges();
     }
 }
예제 #21
0
 private void gridEditoras_SelectionChanged(object sender, EventArgs e)
 {
     int editoraIdFiltrada = 0;
     if (gridEditoras.CurrentRow != null)
         editoraIdFiltrada = Convert.ToInt16(gridEditoras.CurrentRow.Cells["EditoraId"].Value);
     using (var context = new BibliotecaContext())
     {
         var listaLivros = context
             .Livros.Where(x => x.EditoraId == editoraIdFiltrada)
             .ToList();
         gridLivros.DataSource = listaLivros;
         gridLivros.Columns["Editora"].Visible = false;
         metroLabel2.Text = "Lista de Livros da Editora: " + gridEditoras.CurrentRow.Cells["Descricao"].Value.ToString();
     }
 }
예제 #22
0
        private void frmEditoraConsulta_Load(object sender, EventArgs e)
        {
            //Expressão Lambra para ordenar a lista de editoras 
            using (var context = new BibliotecaContext())
            {
                var listaEditoras = context.Editoras.OrderBy(x => x.Descricao).ToList<Editora>();
                gridEditoras.DataSource = listaEditoras;
                gridEditoras.Columns["Livros"].Visible = false;

                var listaLivros = context.Livros.OrderBy(x => x.Titulo).ToList();
                gridLivros.DataSource = listaLivros;
                gridLivros.Columns["Editora"].Visible = false;
            }

        }
예제 #23
0
 public static void Create(Clasificacion clasificacion)
 {
     try {
         using (var ctx = new BibliotecaContext()) {
             if (string.IsNullOrEmpty(clasificacion.Descripcion))
             {
                 clasificacion.Descripcion = "";
             }
             ctx.Clasificaciones.AddObject(clasificacion);
             ctx.SaveChanges();
         }
     } catch (Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
예제 #24
0
        public ActionResult Register(Loginnn account)
        {
            if (ModelState.IsValid)
            {
                using (BibliotecaContext db = new BibliotecaContext())
                {
                    db.Loginuri.Add(account);
                    db.SaveChanges();
                }
                ModelState.Clear();
                //   ViewBag.Message= account.ProductId + " " +
            }

            return(View());
        }
예제 #25
0
 public static void update(PrestamoViewModel pvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Prestamo p = ctx.Prestamos.SingleOrDefault(b => b.PrestamoId == pvm.PrestamoId);
         if (p != null)
         {
             p.fechaDevolucionTope = pvm.fechaDevolucionTope;
             p.fechaPrestamo       = pvm.fechaPrestamo;
             p.usuario_UsuarioId   = pvm.UsuarioId;
             p.libro_LibroID       = pvm.LibroId;
             ctx.SaveChanges();
         }
     }
 }
예제 #26
0
 public static void Update(Pais pais)
 {
     using (var ctx = new BibliotecaContext()) {
         Pais p1 = ctx.Paises.Where(p => p.Nombre == pais.Nombre).FirstOrDefault();
         if (p1 != null && p1.Id != pais.Id)
         {
             throw new Excepcion("Ya existe un País con el nombre '" + pais.Nombre + "'");
         }
         p1            = ctx.Paises.Where(p => p.Id == pais.Id).FirstOrDefault();
         p1.Estado     = pais.Estado;
         p1.Gentilicio = pais.Gentilicio;
         p1.Nombre     = pais.Nombre;
         ctx.SaveChanges();
     }
 }
예제 #27
0
        public Mutacion(BibliotecaContext context)
        {
            _context = context;

            Field <AutoresType>(
                "crearAutor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <AutoresInputType> > {
                Name = "autores"
            }),
                resolve: context =>
            {
                var autor = context.GetArgument <Autores>("autores");
                _context.Autores.Add(autor);
                _context.SaveChanges();
                return(autor);
            });



            Field <AutoresType>(
                "modificarAutor",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AutoresInputType> > {
                Name = "autores"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }
                    ),
                resolve: context =>
            {
                var autor = context.GetArgument <Autores>("autores");
                var id    = context.GetArgument <int>("id");

                var autordb = _context.Autores.Find(id);
                if (autordb == null)
                {
                    context.Errors.Add(new ExecutionError("Ups!!, el id no existe!! :("));
                    return(null);
                }

                autordb.Nombre       = autor.Nombre;
                autordb.Nacionalidad = autor.Nacionalidad;
                _context.SaveChanges();

                return(autordb);
            });
        }
예제 #28
0
        public static void  verificaSeUsuarioAdminExiste(BibliotecaContext bc)
        {
            IQueryable <Usuario> userEncontrado = bc.Usuarios.Where(u => u.login == "admin");

            if (userEncontrado.ToList().Count == 0)
            {
                Usuario admin = new Usuario();
                admin.login = "******";
                admin.senha = Criptografo.TextoCriptografado("123");
                admin.tipo  = Usuario.ADMIN;
                admin.nome  = "Administrador";

                bc.Usuarios.Add(admin);
                bc.SaveChanges();
            }
        }
예제 #29
0
 public static void update(LibroViewModel lvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Libro l = ctx.Libros.SingleOrDefault(b => b.LibroID == lvm.LibroId);
         if (l != null)
         {
             l.titulo         = lvm.titulo;
             l.autor          = lvm.titulo;
             l.isbn           = lvm.isbn;
             l.genero         = lvm.genero;
             l.cantEjemplares = lvm.cantEjemplares;
             ctx.SaveChanges();
         }
     }
 }
예제 #30
0
 public static void update(UsuarioViewModel uvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Usuario u = ctx.Usuarios.SingleOrDefault(b => b.UsuarioId == uvm.UsuarioId);
         if (u != null)
         {
             u.nombre          = uvm.nombre;
             u.apellido        = uvm.apellido;
             u.tipoDocumento   = uvm.tipoDocumento;
             u.numeroDocumento = uvm.numeroDocumento;
             u.email           = uvm.email;
             ctx.SaveChanges();
         }
     }
 }