コード例 #1
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
        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;
            }
        }
コード例 #2
0
ファイル: LenderData.cs プロジェクト: moriahavlin/bookabook
 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);
 }
コード例 #3
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
 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;
     }
 }
コード例 #4
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
 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)
     {
     }
 }
コード例 #5
0
ファイル: LenderData.cs プロジェクト: moriahavlin/bookabook
 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);
 }
コード例 #6
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
 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;
     }
 }
コード例 #7
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
        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;
            }
        }
コード例 #8
0
ファイル: LenderData.cs プロジェクト: moriahavlin/bookabook
 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);
 }
コード例 #9
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
        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;
            }
        }
コード例 #10
0
ファイル: BooksData.cs プロジェクト: moriahavlin/bookabook
        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;
            }
        }