示例#1
0
 public static Pais Get(int PaisId)
 {
     using(var ctx = new BibliotecaContext()) {
         Pais p1 = ctx.Paises.Where(p => p.Id == PaisId).FirstOrDefault();
         return p1;
     }
 }
示例#2
0
 public static void CambiarEstado(int PaisId, int estado)
 {
     using(var ctx = new BibliotecaContext()) {
         ctx.Paises.Where(p => p.Id == PaisId).FirstOrDefault().Estado = estado;
         ctx.SaveChanges();
     }
 }
 public static void CambiarEstado(int ClasificacionId, int estado)
 {
     using(var ctx = new BibliotecaContext()) {
         ctx.Clasificaciones.Where(c => c.Id == ClasificacionId).FirstOrDefault().Estado = estado;
         ctx.SaveChanges();
     }
 }
示例#4
0
 public static void CambiarEstadoEjemplar(int EjemplarId, int estado)
 {
     using(var ctx = new BibliotecaContext()) {
         ctx.Ejemplares.Where(e => e.Id == EjemplarId).FirstOrDefault().Estado = estado;
         ctx.SaveChanges();
     }
 }
示例#5
0
 public static void CambiarEstado(int LibroId, int estado)
 {
     using(var ctx = new BibliotecaContext()) {
         ctx.Libros.Where(l => l.Id == LibroId).FirstOrDefault().Estado = estado;
         ctx.SaveChanges();
     }
 }
示例#6
0
 public static void Create(Pais pais)
 {
     using(var ctx = new BibliotecaContext()) {
         if(ctx.Paises.Where(p => p.Nombre == pais.Nombre).Count() > 0)
             throw new Excepcion("Ya existe un País con el nombre '" + pais.Nombre + "'");
         ctx.Paises.AddObject(pais);
         ctx.SaveChanges();
     }
 }
示例#7
0
 public static int CambiarEstado(int PaisId)
 {
     using(var ctx = new BibliotecaContext()) {
         Pais p1 = ctx.Paises.Where(p => p.Id == PaisId).FirstOrDefault();
         p1.Estado = (p1.Estado + 1) % 2;
         ctx.SaveChanges();
         return p1.Estado;
     }
 }
示例#8
0
 public static int CambiarEstadoEjemplar(int EjemplarId)
 {
     using(var ctx = new BibliotecaContext()) {
         Ejemplar e1 = ctx.Ejemplares.Where(e => e.Id == EjemplarId).FirstOrDefault();
         e1.Estado = (e1.Estado + 1) % 2;
         ctx.SaveChanges();
         return e1.Estado;
     }
 }
示例#9
0
 public static int CambiarEstado(int LibroId)
 {
     using(var ctx = new BibliotecaContext()) {
         Libro l1 = ctx.Libros.Where(l => l.Id == LibroId).FirstOrDefault();
         l1.Estado = (l1.Estado + 1) % 2;
         ctx.SaveChanges();
         return l1.Estado;
     }
 }
示例#10
0
 public static void Delete(int PaisId)
 {
     using(var ctx = new BibliotecaContext()) {
         try {
             ctx.Paises.DeleteObject(ctx.Paises.Where(p => p.Id == PaisId).FirstOrDefault());
             ctx.SaveChanges();
         } catch {
             throw new Excepcion("No se puede eliminar el registro, tiene participación en alguna transacción");
         }
     }
 }
示例#11
0
 public static Editorial Get(int EditorialId)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             Editorial e1 = ctx.Editoriales.Include("Pais").Where(e => e.Id == EditorialId).FirstOrDefault();
             return e1;
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
 public static Clasificacion Get(int ClasificacionId)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             Clasificacion c1 = ctx.Clasificaciones.Where(c => c.Id == ClasificacionId).FirstOrDefault();
             return c1;
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#13
0
 public static void CambiarEstado(int EditorialId, int estado)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             ctx.Editoriales.Where(e => e.Id == EditorialId).FirstOrDefault().Estado = estado;
             ctx.SaveChanges();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#14
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);
     }
 }
 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);
     }
 }
 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);
     }
 }
示例#17
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);
     }
 }
示例#18
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();
     }
 }
示例#19
0
 public static void Create(Autor autor)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             if(string.IsNullOrEmpty(autor.Nombres))
                 autor.Nombres = "";
             autor.Pais = ctx.Paises.Where(p => p.Id == autor.Pais.Id).FirstOrDefault();
             ctx.Autores.AddObject(autor);
             ctx.SaveChanges();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#20
0
 public static bool Delete(int EditorialId)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             try {
                 ctx.Editoriales.DeleteObject(ctx.Editoriales.Where(e => e.Id == EditorialId).FirstOrDefault());
                 ctx.SaveChanges();
                 return true;
             } catch {
                 return false;
             }
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#21
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();
     }
 }
示例#22
0
 public static void Delete(int AutorId)
 {
     using(var ctx = new BibliotecaContext()) {
         try {
             ctx.Autores.DeleteObject(ctx.Autores.Where(a => a.Id == AutorId).FirstOrDefault());
             ctx.SaveChanges();
         } catch {
             throw new Excepcion("No se puede eliminar el registro, tiene participación en alguna transacción");
         }
     }
     //try {
     //    using(var ctx = new BibliotecaContext()) {
     //        try {
     //            ctx.Autores.DeleteObject(ctx.Autores.Where(a => a.Id == AutorId).FirstOrDefault());
     //            ctx.SaveChanges();
     //            return true;
     //        } catch {
     //            return false;
     //        }
     //    }
     //} catch(Exception ex) {
     //    throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     //}
 }
示例#23
0
 public static List<Editorial> List2()
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             return ctx.Editoriales.Include("Pais").OrderBy(e => e.Nombre).ToList();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#24
0
 public static List<Pais> ListActivos()
 {
     using(var ctx = new BibliotecaContext()) {
         return ctx.Paises.Where(p => p.Estado == 1).OrderBy(p => p.Nombre).ToList();
     }
 }
示例#25
0
 public static List<Pais> List()
 {
     using(var ctx = new BibliotecaContext()) {
         return ctx.Paises.OrderBy(p => p.Nombre).ToList();
     }
 }
示例#26
0
 public static Autor Get(int AutorId)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             Autor a1 = ctx.Autores.Include("Pais").Where(a => a.Id == AutorId).FirstOrDefault();
             return a1;
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#27
0
 public static List<Autor> List()
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             return ctx.Autores.OrderBy(a => a.Apellidos).ToList();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
示例#28
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);
     }
 }
 public static List<Clasificacion> ListActivos()
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             return ctx.Clasificaciones.Where(c => c.Estado == 1).OrderBy(c => c.Nombre).ToList();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }
 public static void Update(Clasificacion clasificacion)
 {
     try {
         using(var ctx = new BibliotecaContext()) {
             Clasificacion c1 = ctx.Clasificaciones.Where(c => c.Id == clasificacion.Id).FirstOrDefault();
             c1.Abreviatura = clasificacion.Abreviatura;
             if(string.IsNullOrEmpty(clasificacion.Descripcion))
                 clasificacion.Descripcion = "";
             c1.Descripcion = clasificacion.Descripcion;
             c1.Estado = clasificacion.Estado;
             c1.Nombre = clasificacion.Nombre;
             ctx.SaveChanges();
         }
     } catch(Exception ex) {
         throw new Exception("Ocurrio un error al obtener los datos, verifique la conexion con el servidor", ex);
     }
 }