Beispiel #1
0
 //mv 05-03-2019
 public static bool returnBook(int idLender)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             LendsTable lend = db.LendsTable.Where(l => l.id == idLender).FirstOrDefault();
             if (lend != null)
             {
                 if (lend.statusCode == 2)
                 {
                     lend.BooksTable.isBorrowed = false;
                     lend.statusCode            = 4;
                     lend.date = DateTime.Now;
                     db.SaveChanges();
                     return(true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(false);
 }
Beispiel #2
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;
            }
        }
Beispiel #3
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);
 }
Beispiel #4
0
 public static int isExist(string email, string password)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             //0=לא קיים
             //-1=לא תקין
             bool exist = db.UsersTable.Any(x => x.email == email);
             if (exist == false)
             {
                 return(0);
             }
             UsersTable u = db.UsersTable.Where(x => x.email == email && x.password == password).FirstOrDefault();
             if (u == null)
             {
                 return(-1);
             }
             return(u.id);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
 public static List <RatingTable> GetAllRatingByIdBook(int idBook)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.RatingTable.Where(b => b.bookId == idBook).ToList());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
 public static bool isMailExist(string email)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.UsersTable.Any(x => x.email == email));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
 public static List <BooksTable> getAllUsersBooksByIDU(int id)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.BooksTable.Where(book => book.lenderId == id).ToList());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #8
0
 public static void removeWaitingToBookByIdWaiting(waitingForAbookTable watingToboook)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.waitingForAbookTable.Remove(watingToboook);
         }
     }
     catch (Exception ex)
     {
         // throw ex;
     }
 }
Beispiel #9
0
 public static List <waitingForAbookTable> GetAllWaitingForBook(int idB)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.waitingForAbookTable.Where(x => x.bookCode == idB).ToList());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #10
0
 public static UsersTable getUserByEmail(string email)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.UsersTable.Where(user => user.email == email).SingleOrDefault());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #11
0
 public static List <UsersTable> getAllUsers()
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.UsersTable.ToList());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #12
0
 public static UsersTable getUserById(int id)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.UsersTable.Where(user => user.id == id).SingleOrDefault());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #13
0
 public static List <BooksTable> getAllBooks()
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             List <BooksTable> res = db.BooksTable.Where(b => b.isDeleted != true).ToList();
             return(res);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #14
0
 public static LendsTable getLendsByIdBorrow(int idBorrow)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.LendsTable.Where(l => l.id == idBorrow).FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(null);
 }
Beispiel #15
0
 //הספרים שלי שמושאלים אצל אנשים אחרים
 public static List <LendsTable> getAllmyBooksThatBorrowed(int idU)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             List <LendsTable> lt = db.LendsTable.Where(l => (l.statusCode == 2) && l.BooksTable.lenderId == idU).ToList();
             return(lt);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #16
0
 public static bool RateBook(RatingTable rating)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.RatingTable.Add(rating);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #17
0
 public static UsersTable InsertUser(UsersTable newUser)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.UsersTable.Add(newUser);
             db.SaveChanges();
             return(newUser);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #18
0
 public static string deleteUser(int uId)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.UsersTable.Remove(db.UsersTable.Find(uId));
             db.SaveChanges();
         }
         return("ok");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #19
0
 public static List <LendsTable> getMyBooksNeedToBeReturned(int idU)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             DateTime          dt = DateTime.Today.AddDays(-60);
             List <LendsTable> lt = db.LendsTable.Where(l => (l.statusCode == 2) && l.BooksTable.lenderId == idU && dt > l.date).ToList();
             return(lt);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #20
0
 public static List <LendsTable> getBooksUserDidntReturn(int idU)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             DateTime          dt = DateTime.Today.AddDays(-60);
             List <LendsTable> lt = db.LendsTable.Where(l => l.statusCode == 2 && l.borrowerId == idU && dt > l.date).ToList();
             return(lt);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #21
0
        public static BooksTable getBookById(int id)
        {
            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    return(db.BooksTable.Where(book => book.id == id)

                           .SingleOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #22
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;
     }
 }
Beispiel #23
0
 //?????????????????????????
 public static string updateUser(UsersTable u)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             UsersTable u1 = db.UsersTable.Where(i => i.id == u.id).First();
             u1.birthDate = u.birthDate;
             db.SaveChanges();
         }
         return("ok");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #24
0
 //mv 05-03-2019
 //הספרים שאני משאיל אותם - נמצאים אצלי
 public static List <LendsTable> getBorrowedBookByUser(int idU)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             //יחזיר רק את הספרים שכרגע מושאלים
             //mv 05-03-2019
             List <LendsTable> lt = db.LendsTable.Where(l => (l.statusCode == 2) && l.borrowerId == idU).ToList();
             return(lt);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #25
0
 public static void addBookToMybasket(MyBasketOfBooks bas)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             db.MyBasketOfBooks.Add(bas);
             //????????????????????????????????????????????????????
             db.SaveChanges();
         }
         return;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #26
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)
     {
     }
 }
Beispiel #27
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);
 }
Beispiel #28
0
 public static BooksTable getBookAndOtherDetailesToStatisckById(int id)
 {
     try
     {
         using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
         {
             return(db.BooksTable.Where(book => book.id == id)
                    .Include(x => x.RatingTable)
                    .Include(x => x.LendsTable)
                    .Include(x => x.UsersTable)
                    .Include(x => x.MyBasketOfBooks)
                    .SingleOrDefault());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #29
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;
     }
 }
Beispiel #30
0
        public static int rateBook(RatingTable b)
        {
            int idB;

            try
            {
                using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities())
                {
                    db.RatingTable.Add(b);
                    //????????????????????????????????????????????????????
                    db.SaveChanges();
                    idB = b.id;
                }
                return(idB);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }