Exemplo n.º 1
0
        public IEnumerable<Book> GetAuthorBooks(string authorName)
        {
            List<Book> result;
            string firstWord = authorName;
            string secondWord = authorName;

            if (authorName.Contains(' '))
            {
                firstWord = authorName.Split(' ')[0];
                secondWord = authorName.Split(' ')[1];
                using (var context = new TheLibraryEntities())
                {
                    result = (from book in context.Books.Include("Author")
                              where (book.Author.Name.Contains(firstWord) && book.Author.Lastname.Contains(secondWord))
                              || (book.Author.Name.Contains(secondWord) && book.Author.Lastname.Contains(firstWord))
                              select book).ToList();
                }
            }
            else
            {
                using (var context = new TheLibraryEntities())
                {
                    result = (from book in context.Books.Include("Author")
                              where book.Author.Name.Contains(authorName) || book.Author.Lastname.Contains(authorName)
                              select book).ToList();
                }
            }

            return result;
        }
Exemplo n.º 2
0
 public IEnumerable<Book> GetAllBooks()
 {
     List<Book> result;
     using (var context = new TheLibraryEntities())
     {
         result = context.Books.Include("Author").ToList();
     }
     return result;
 }
Exemplo n.º 3
0
 public IEnumerable<Author> GetAllAuthors()
 {
     List<Author> result;
     using (var context = new TheLibraryEntities())
     {
         result = context.Authors.ToList();
     }
     return result;
 }
Exemplo n.º 4
0
        public IEnumerable<Author> GetAllNamesakes()
        {
            List<Author> result = new List<Author>();
            using (var context = new TheLibraryEntities())
            {
                var namesakes = (from author in context.Authors
                                 group author by author.Lastname into g
                                 select g).Where(k => k.Count() > 1).ToList();

                foreach (var namesake in namesakes)
                {
                    result.AddRange(namesake);
                }
            }
            return result;
        }
Exemplo n.º 5
0
 public IEnumerable<Book> GetAverageRateBook(int year)
 {
     IEnumerable<Book> result = new List<Book>();
     using (var context = new TheLibraryEntities())
     {
         int countBook = (from book in context.Books
                          where book.BookIssuances.Where(i => i.IssuanceDate.Year == year).Count() > 0
                          select book).Count();
         int countIssuance = context.BookIssuances.Where(c => c.IssuanceDate.Year == year).Count();
         if (countBook != 0)
         {
             result = (from book in context.Books.Include("Author")
                       where book.BookIssuances.Where(i => i.IssuanceDate.Year == year).Count() >= countIssuance / countBook
                       select book).ToList();
         }
     }
     return result;
 }
Exemplo n.º 6
0
        public IEnumerable<Author> GetPopularInYear(int year)
        {
            IEnumerable<Author> result;
            using (var context = new TheLibraryEntities())
            {
                    result = (from author in context.Authors
                                   select new
                                   {
                                       Author = author,
                                       PopularityIndex = (from book in author.Books
                                                          select (from issuance in book.BookIssuances
                                                                  where issuance.IssuanceDate.Year == year
                                                                  select issuance).Count()
                                                          ).Sum()
                                   }).Where(a => a.PopularityIndex > 0)
                              .OrderByDescending(a => a.PopularityIndex)
                              .Select(a => a.Author).Take(1).ToList();

            }
            return result;
        }
Exemplo n.º 7
0
 public IEnumerable<Book> GetUndefinedBook(string year, string name)
 {
     IEnumerable<Book> result;
     int publish;
     if (int.TryParse(year, out publish))
     {
         using (var context = new TheLibraryEntities())
         {
             result = (from book in context.Books
                       where (book.PublishDate.Value.Year == publish && book.Name.Contains(name))
                       select book).ToList();
         }
     }
     else
     {
         using (var context = new TheLibraryEntities())
         {
             result = (from book in context.Books
                       where book.Name.Contains(name)
                       select book).ToList();
         }
     }
     return result;
 }