Пример #1
0
 public bool CanBorrowBooks(int usuarioId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Prestamos.Count(x => x.UsuarioId == usuarioId) < 3);
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #2
0
 public Libros FindBook(int libroId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Libros.Find(libroId));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #3
0
 public bool ExistBook(string titulo)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Libros.Any(x => x.Titulo.Trim() == titulo));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #4
0
 public bool HasFines(int usuarioId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Multas.Any(x => x.UsuarioId == usuarioId));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #5
0
 public List <Prestamos> GetOwnBorrowedBooks(int usuarioId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Prestamos.Where(x => x.UsuarioId == usuarioId).ToList());
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #6
0
 public bool IsBookBorrowed(int libroId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Prestamos.ToList().Any(x => x.LibroId == libroId));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #7
0
 public bool ExistUser(string nombreUsuario)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Usuarios.Any(x => x.Nombre.Trim() == nombreUsuario));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #8
0
 public Usuarios FindUsuario(string nombre)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Usuarios.FirstOrDefault(x => x.Nombre.Trim() == nombre));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #9
0
 public List <Libros> GetAllBooks()
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             return(db.Libros.ToList());
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #10
0
 public Libros FindBook(string titulo)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             var id = db.Libros.ToList().First(x => x.Titulo.Trim() == titulo).Id;
             return(db.Libros.Find(id));
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #11
0
 public void PayFine(int usuarioId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             var multa = db.Multas.First(x => x.UsuarioId == usuarioId);
             db.Multas.Remove(multa);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #12
0
 public bool ReturnBook(int id)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             var prestamo = db.Prestamos.First(x => x.LibroId == id);
             db.Prestamos.Remove(prestamo);
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #13
0
 public bool RegistreBook(string name)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             db.Libros.Add(new Libros {
                 Titulo = name
             });
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #14
0
 public bool AddFine(int usuarioId)
 {
     using (var db = new BBDD_BibliotecaEntities())
     {
         try
         {
             db.Multas.Add(new Multas
             {
                 UsuarioId = usuarioId
             });
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
Пример #15
0
        public bool CrearUsuario(string nombreUsuario)
        {
            using (var db = new BBDD_BibliotecaEntities())
            {
                try
                {
                    db.Usuarios.Add(new Usuarios
                    {
                        Nombre = nombreUsuario
                    });

                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Пример #16
0
        public bool LoanBook(int libroId, int usuarioId)
        {
            using (var db = new BBDD_BibliotecaEntities())
            {
                try
                {
                    db.Prestamos.Add(new Prestamos
                    {
                        LibroId       = libroId,
                        UsuarioId     = usuarioId,
                        FechaPrestamo = DateTime.Now.Date
                    });

                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }