Exemple #1
0
        public static List <BooksTable> getAllMyBasket(int idU)
        {
            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    var mybasket            = db.MyBasketOfBooks.Where(x => x.idUser == idU).ToList();
                    List <BooksTable> books = new List <BooksTable>();

                    foreach (var item in mybasket)
                    {
                        BooksTable x = db.BooksTable.Where(b => b.id == item.idBook).FirstOrDefault();
                        if (x != null)
                        {
                            books.Add(x);
                        }
                    }
                    return(books.Where(b => b.isDeleted != true).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
 public static bool rejectBorrow(int idBorrow)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             LendsTable lend = db.LendsTable.Where(l => l.id == idBorrow).FirstOrDefault();
             if (lend != null)
             {
                 if (lend.statusCode == 1)
                 {
                     lend.statusCode = 3;
                     BooksTable bt = db.BooksTable.Where(b => b.id == lend.bookId).FirstOrDefault();
                     if (bt != null)
                     {
                         bt.isBorrowed = false;
                     }
                     db.SaveChanges();
                     return(true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Exemple #3
0
 public static void deleteBook(int idB)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             BooksTable b = db.BooksTable.Where(book => book.id == idB).First();
             b.isDeleted = true;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #4
0
 public static void PromoteNumberOfViewers(int idBook)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             BooksTable bt = db.BooksTable.Where(b => b.id == idBook).FirstOrDefault();
             if (bt != null)
             {
                 bt.numberOfViewers++;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #5
0
 public static bool borrowBook(LendsTable lend)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.LendsTable.Add(lend);
             BooksTable b = db.BooksTable.Where(x => x.id == lend.bookId).FirstOrDefault();
             b.isBorrowed = true;
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Exemple #6
0
 public static void saveImageName(int idBook, string bookName)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             BooksTable book = db.BooksTable.Where(b => b.id == idBook).FirstOrDefault();
             if (book != null)
             {
                 book.picNAme = bookName;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #7
0
        public static int InsertBook(BooksTable b)
        {
            int idB;

            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    db.BooksTable.Add(b);
                    //????????????????????????????????????????????????????
                    db.SaveChanges();
                    idB = b.id;
                }
                return(idB);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #8
0
 public static bool checkIfBookIsBorrow(int idB)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             BooksTable booktable = db.BooksTable.Where(x => x.id == idB).FirstOrDefault();
             if (booktable != null)
             {
                 if (booktable.isBorrowed == true)
                 {
                     return(true);
                 }
             }
         }
     }
     catch
     {
     }
     return(false);
 }
Exemple #9
0
        public static int[] numWomenRead(int idBook)
        {
            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    BooksTable bt = db.BooksTable.Where(b => b.id == idBook).FirstOrDefault();
                    if (bt != null)
                    {
                        int   numWomen    = bt.LendsTable.Where(l => (l.statusCode == 2 || l.statusCode == 4) && l.UsersTable.genderId == 1).Count();
                        int   numMen      = bt.LendsTable.Where(l => (l.statusCode == 2 || l.statusCode == 4) && l.UsersTable.genderId == 2).Count();
                        int[] WomenAndMen = { numWomen, numMen };
                        return(WomenAndMen);
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #10
0
        public static void editBook(BooksTable book)
        {
            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    BooksTable booktable = db.BooksTable.Where(x => x.id == book.id).FirstOrDefault();

                    if (booktable != null)
                    {
                        if (book.autherId != 0)
                        {
                            booktable.autherId = book.autherId;
                        }
                        else
                        {
                            //  db.PublishingTable.
                            booktable.AutherTable = new AutherTable()
                            {
                                name = book.AutherTable.name
                            };
                        }
                        if (book.nameId != 0)
                        {
                            booktable.nameId = book.nameId;
                        }
                        else
                        {
                            //  db.PublishingTable.
                            booktable.BooksNameTable = new BooksNameTable()
                            {
                                name = book.BooksNameTable.name
                            };
                        }


                        booktable.categoryId  = book.categoryId;
                        booktable.description = book.description;
                        booktable.numOfPages  = book.numOfPages;
                        if (book.publishingId != 0)
                        {
                            booktable.publishingId = book.publishingId;
                        }
                        else
                        {
                            booktable.PublishingTable = new PublishingTable()
                            {
                                name = book.PublishingTable.name
                            };
                        }
                    }
                    //????????????????????????????????????????????????????
                    db.SaveChanges();
                }
                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }