示例#1
0
        public static List <Book> SearchBooks()
        {
            library_dbEntities dbContext = new library_dbEntities();
            var books = from b in dbContext.Books select b;

            return(books.ToList());
        }
示例#2
0
 public List <Category> AllCategories()
 {
     using (library_dbEntities context = new library_dbEntities())
     {
         return(context.Categories.Select(category => category).ToList <Category>());
     }
 }
示例#3
0
        public static List <Book> ListBooksByCategory(int categoryId)
        {
            library_dbEntities dbContext = new library_dbEntities();
            var books = from b in dbContext.Books
                        join c in dbContext.Categories on b.CategoryId equals c.CategoryId
                        where c.CategoryId == categoryId
                        select b;

            return(books.ToList());
        }
示例#4
0
 public static bool Insert(BorrowedBy borrowed)
 {
     try
     {
         library_dbEntities dbContext = new library_dbEntities();
         dbContext.BorrowedBies.Add(borrowed);
         dbContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#5
0
        public static List <Book> SearchBooks(String keyword, int categoryId)
        {
            library_dbEntities dbContext = new library_dbEntities();
            var books = from b in dbContext.Books
                        join c in dbContext.Categories on b.CategoryId equals c.CategoryId
                        where c.CategoryId == categoryId
                        select b;

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                books = books.Where(b => b.BookName.ToLower().Contains(keyword.ToLower()));
            }
            return(books.ToList());
        }
示例#6
0
        public static bool CreateUser(User user)
        {
            library_dbEntities dataContext = new library_dbEntities();

            try
            {
                dataContext.Users.Add(user);
                dataContext.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#7
0
        public static List <BorrowedBy> SearchBorrowedBooks(int memberId)
        {
            library_dbEntities dbContextBorrowed = new library_dbEntities();
            members_dbEntities memberDbContext   = new members_dbEntities();
            var memberIds = (from m in memberDbContext.Members
                             where m.MemberId == memberId
                             select m).ToArray();

            var borrowedMemberIds = (from m in dbContextBorrowed.BorrowedBies
                                     select m).ToArray();

            var books = (from bm in borrowedMemberIds where bm.returned == 0
                         join m in memberIds
                         on bm.MemberId equals m.MemberId
                         select bm);

            return(books.ToList());
        }
示例#8
0
        public static bool Update(BorrowedBy borrowed)
        {
            try
            {
                library_dbEntities dbContextBorrowed = new library_dbEntities();
                BorrowedBy         borrowedBy        = (from bb in dbContextBorrowed.BorrowedBies
                                                        where bb.BorrowedId == borrowed.BorrowedId
                                                        select bb).SingleOrDefault();

                borrowedBy.returned = borrowed.returned;
                dbContextBorrowed.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#9
0
        /**
         * Fetches user by username and password. If the user exists in the database, this
         * returns true if the credentials match with a record. If not, this returns false.
         **/
        public static bool Login(User user)
        {
            library_dbEntities dataContext = new library_dbEntities();

            try
            {
                var memberName = dataContext.Users.First().username;
                Console.WriteLine(memberName);
                User logingUser = (from User in dataContext.Users where User.username.Equals(user.username) && User.password.Equals(user.password) select User).FirstOrDefault();
                if (logingUser != null)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#10
0
        public static int CountPublications(int category)
        {
            library_dbEntities dbContext = new library_dbEntities();

            return((from b in dbContext.Books where b.CategoryId == category select b).Count());
        }
示例#11
0
        public static Book FindBook(int bookId)
        {
            library_dbEntities dbContext = new library_dbEntities();

            return((from b in dbContext.Books where b.BookId == bookId select b).First());
        }