예제 #1
0
 public static void ListAllBooks()
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     var result = from d in dt.Books
                  orderby d.TITLE
                  select d.TITLE;
     foreach (var item in result)
     {
         Console.WriteLine(item);
     }
 }
예제 #2
0
 public static void GetBooksSortedByAuthor()
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     var result = from b in dt.Books
                  join a in dt.AUTHORBOOKs on b.ID equals a.BOOKID
                  join au in dt.AUTHORs on a.AUTHORID equals au.AUTHORID
                  orderby au.FIRSTNAME
                  select new { NAME = au.FIRSTNAME,LASTNAME= au.LASTNAME ,BOOK = b.TITLE };
     foreach (var item in result)
     {
         Console.WriteLine($"{item.NAME} {item.LASTNAME} -  {item.BOOK}");
     }
 }
예제 #3
0
 public static void GetBookSoretedBYGenre()
 {
     Dictionary<string, string[]> dic = new Dictionary<string, string[]>();
     DataClasses1DataContext dt = new DataClasses1DataContext();
     var result = from b in dt.Books
                  join g in dt.BOOKGENREs on b.ID equals g.BOOKID into genresGroup
                  let genreNames = (from g in genresGroup
                                    orderby g.GENRE.NAME
                                     select g.GENRE.NAME)
                  orderby genreNames.First()
                  select new { GENRES = genreNames, BOOK = b.TITLE };
     foreach (var item in result)
     {
         Console.WriteLine($"{item.BOOK}  { string.Join(", ", item.GENRES)}");
     }
 }
예제 #4
0
 public static void GetAllGenresFromAuthor(int id)
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     var result = from b in dt.Books
                  join ab in dt.AUTHORBOOKs on b.ID equals ab.BOOKID           
                  join a in dt.AUTHORs on ab.AUTHORID equals a.AUTHORID
                  join bg in dt.BOOKGENREs on b.ID equals bg.BOOKID
                  into genresGropu 
                  let genresNames =(from g in genresGropu
                                    orderby g.GENRE.NAME
                                    select g.GENRE.NAME)
                                    orderby genresNames.First()
                  where a.AUTHORID.Equals(id)
                  select new { AUTNAME = a.FIRSTNAME, AutLastName=a.LASTNAME,GENREs=genresNames };
     foreach (var item in result.ToList())
     {
         Console.WriteLine($"{item.AUTNAME} {item.AutLastName} - {string.Join(",",item.GENREs)}");
     }
 }
예제 #5
0
   public static void GetAllBooksByAuthor(int id)
   {
       DataClasses1DataContext dt = new DataClasses1DataContext();
       var result = from b in dt.Books
                    join ab in dt.AUTHORBOOKs on b.ID equals ab.BOOKID
                    join a in dt.AUTHORs on ab.AUTHORID equals a.AUTHORID
                    where a.AUTHORID.Equals(id)
                    select new { BOOK = b.TITLE, AUT = a.FIRSTNAME };
       var name = from a in dt.AUTHORs
                  where a.AUTHORID.Equals(id)
                  select new { FRNAME = a.FIRSTNAME, LAST = a.LASTNAME };
       foreach (var item in name)
       {
           Console.WriteLine($"{item.FRNAME}  {item.LAST}");
       }
       foreach (var item in result)
       {
           Console.WriteLine(item.BOOK);
       }
 
   }
예제 #6
0
 public static void InsertAuthor(AUTHOR author)
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     dt.AUTHORs.InsertOnSubmit(author);
     dt.SubmitChanges();
 }
예제 #7
0
 public static void InsertBook(Book book)
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     dt.Books.InsertOnSubmit(book);
     dt.SubmitChanges();
 }
예제 #8
0
        public static void LoanBook(int bookID, int userID)
        {
            DataClasses1DataContext dt = new DataClasses1DataContext();
            var loanedBooks = from l in dt.LOANEDBOOKSBYUSERs
                         where l.USERID.Equals(userID)
                         select new { LOADNEDBOOKS = l.BOOKID };
            int couterOfLoanedBooks = 0;
            foreach (var item in loanedBooks)
            {
                couterOfLoanedBooks++;
            }
            if (couterOfLoanedBooks>3)
            {
                Console.WriteLine("The maximum numbers that you can load is 3 ");
                return;
            }
            else
            {

            }

        }
예제 #9
0
 public static void BookInfoTitle(string title)
 {
     DataClasses1DataContext dt = new DataClasses1DataContext();
     var result = from b in dt.Books
                  join ab in dt.AUTHORBOOKs on b.ID equals ab.BOOKID
                  join a in dt.AUTHORs on ab.AUTHORID equals a.AUTHORID
                  where b.TITLE.Contains(title)
                  select new
                  {
                      TITLE = b.TITLE,
                      DESC = b.DESCRIPTION,
                      DATEP = b.DATEPUBLISHED,
                      PUBLISHE = b.PUBLISHER,
                      PAGES = b.PAGES,
                      AUTFIRSTNAME = a.FIRSTNAME,
                      AUTLASTNAME = a.LASTNAME,
                      BIRTHDATE = a.YEARBORN,
                      DIED = a.YEARDIED
                  };
     foreach (var item in result)
     {
         Console.Write($"Title: {item.TITLE}\nDESCRIPTION: {item.DESC}\nDATEPUBLISHED: {item.DATEP}\n");
         Console.Write($"PUBLISHER: {item.PUBLISHE}\nPAGES: {item.PAGES}\nINFO ABOUT THE AUTHOR(S):\n");
         Console.Write($"FIRST NAME: {item.AUTFIRSTNAME}\nLAST NAME: {item.AUTLASTNAME}\n");
         Console.Write($"BORN: {item.BIRTHDATE}\nDIED: {item.DIED}\n");
         Console.WriteLine();
     }
 }