Ejemplo n.º 1
0
 public static BookToList CastBookTableToBookLIST(BooksTable bookTable)
 {
     try
     {
         BookToList book = new BookToList()
         {
             numberOfViewers = bookTable.numberOfViewers,
             picNAme         = bookTable.picNAme,
             autherId        = LookupBL.getLookupByCode(Constants.AutherTableName, bookTable.autherId),
             //   categoryId = LookupBL.getLookupByCode(Constants.BooksCategoryTableName, bookTable.categoryId),
             id = bookTable.id,
             // description = bookTable.description,
             //  numOfPages = bookTable.numOfPages,
             isBorrowed = bookTable.isBorrowed,
             // lenderId = bookTable.lenderId,
             nameId = LookupBL.getLookupByCode(Constants.BooksNameTableName, bookTable.nameId),
             //  publishingId = LookupBL.getLookupByCode(Constants.PuplishingTableName, bookTable.publishingId)
         };
         return(book);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public static bool confirmBorrow(int idBorrow)
        {
            bool res = LenderData.confirmBorrow(idBorrow);

            if (res == true)
            {
                LendsTable lendTable = LenderData.getLendsByIdBorrow(idBorrow);
                //השואל
                UsersTable borrow = UserData.getUserById(lendTable.borrowerId);
                BooksTable bt     = BooksData.getBookById(lendTable.bookId);
                //המשאיל
                UsersTable ut       = UserData.getUserById(bt.lenderId);
                string     bookName = LookupBL.getLookupByCode(Constants.BooksNameTableName, bt.nameId).Desc;
                string     message  = "הספר " + bookName + " שביקשת אושר על ידי בעל הספר   : ";
                message += " פרטי בעל הספר ליצירת קשר  : ";
                message += ut.firstName + " " + ut.lastName + ", ";
                message += "טלפון: " + ut.phone + " מייל " + ut.email;
                message += "<br/>  מיקום הספר: רחוב " + ut.address + " " + ut.houseNumber + " " + ut.neighborhood + " " +
                           LookupBL.getLookupByCode(Constants.CitiesTableName, ut.cityCode).Desc;
                //פניה לפונקציה ששולחת מייל על אישור השאלת הספר
                sendEmailFunc.sendEmailAsync(borrow.email, borrow.firstName +
                                             " " + borrow.lastName, message, "אישור השאלת ספר " + bookName);
            }
            return(false);
        }
Ejemplo n.º 3
0
 public static Books CastBookTableToBook(BooksTable bookTable)
 {
     try
     {
         Books book = new Books()
         {
             numberOfViewers = bookTable.numberOfViewers,
             picNAme         = bookTable.picNAme,
             //שליפת פרטי מחבר לפי קוד מחבר
             autherId = LookupBL.getLookupByCode(Constants.AutherTableName, bookTable.autherId),
             //שליפת פרטי קטגורית ספר לפי קוד קטגוריה
             categoryId  = LookupBL.getLookupByCode(Constants.BooksCategoryTableName, bookTable.categoryId),
             id          = bookTable.id,
             description = bookTable.description,
             numOfPages  = bookTable.numOfPages,
             isBorrowed  = bookTable.isBorrowed,
             lenderId    = bookTable.lenderId,
             //שליפת פרטי שם ספר לפי קוד שם
             nameId = LookupBL.getLookupByCode(Constants.BooksNameTableName, bookTable.nameId),
             //שליפת פרטי מוציא לאור לפי קוד מוציא לאור
             publishingId = LookupBL.getLookupByCode(Constants.PuplishingTableName, bookTable.publishingId)
                            // city=LookupBL.getLookupByCode(Constants.CitiesTableName,bookTable.UsersTable.cityCode)
         };
         UsersTable lender = UserData.getUserById(bookTable.lenderId);
         book.city = LookupBL.getLookupByCode(Constants.CitiesTableName, lender.cityCode);
         return(book);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 4
0
 public static User castUserTableToUser(UsersTable userTable)
 {
     try
     {
         User user = new User()
         {
             id           = userTable.id,
             cityCode     = LookupBL.getLookupByCode(Constants.CitiesTableName, userTable.cityCode),
             address      = userTable.address,
             birthDate    = DateTime.Parse(userTable.birthDate.ToString()),
             email        = userTable.email,
             firstName    = userTable.firstName,
             genderId     = LookupBL.getLookupByCode(Constants.GenderTableName, int.Parse(userTable.genderId.ToString())),
             houseNumber  = userTable.houseNumber,
             lastName     = userTable.lastName,
             neighborhood = userTable.neighborhood,
             password     = userTable.password,
             phone        = userTable.phone
         };
         return(user);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
        //
        public static User InsertUser(User u)
        {
            if (UserData.isMailExist(u.email) == true)
            {
                return(null);
            }
            UsersTable ut = new UsersTable()
            {
                address      = u.address,
                birthDate    = u.birthDate,
                email        = u.email,
                firstName    = u.firstName,
                genderId     = u.genderId.Code,
                houseNumber  = u.houseNumber,
                lastName     = u.lastName,
                neighborhood = u.neighborhood,
                password     = u.password,
                phone        = u.phone
            };

            if (u.cityCode.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.CitiesTableName, u.cityCode.Desc) != null)
                {
                    ut.cityCode = LookupBL.getLookupByName(Constants.CitiesTableName, u.cityCode.Desc).Code;
                }
                else
                {
                    ut.CityTable = new CityTable()
                    {
                        name = u.cityCode.Desc
                    }
                };
            }
            else
            {
                ut.cityCode = u.cityCode.Code;
            }
            UsersTable dbUser = UserData.InsertUser(ut);

            if (dbUser != null)
            {
                BooksLibraryDAL.LookupData.refreshLookups();
                User   user    = castUserTableToUser(dbUser);
                string message = "נרשמת בהצלחה לאתר BOOK A BOOK <br/>";
                message += "מחכים לך הרבה מאוד ספרים מעינים , מחכים לך , צוות האתר ";
                sendEmailFunc.sendEmailAsync(user.email, user.firstName + " " + user.lastName, message, "אישור הרשמה");
                return(user);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public static bool borrowBook(int idB, int idU)
        {
            //idU-השואל
            if (BooksLibraryDAL.LenderData.checkIfBookIsBorrow(idB) == false)
            {
                LendsTable lend = new LendsTable();
                lend.bookId       = idB;
                lend.bookIsActive = false;
                lend.borrowerId   = idU;
                lend.date         = DateTime.Now;
                lend.statusCode   = LookupBL.getLookupByName(Constants.lendsStatusTableName, "ממתין לאישור").Code;
                if (BooksLibraryDAL.LenderData.borrowBook(lend) == true)
                {//הספר
                    BooksTable bt = BooksData.getBookById(idB);
                    //המשאיל
                    UsersTable utL = UserData.getUserById(bt.lenderId);
                    //השואל
                    UsersTable ut       = UserData.getUserById(lend.borrowerId);
                    string     bookName = "";

                    if (bt != null)
                    {
                        bookName = LookupBL.getLookupByCode(Constants.BooksNameTableName, bt.nameId).Desc;
                    }
                    string message = "<br/><br/>סיפרך ";
                    message += bookName + " ";
                    message += "ממתין לאישור  על ידי  ";
                    if (ut != null)
                    {
                        message += ut.firstName + " " + ut.lastName + ", " + "טלפון ליצירת קשר:" + ut.phone + "<br/><br/>";
                    }
                    message += "בכדי לאשר את ההשאלה יש להיכנס לאתר ולאשר , המבקש יצור עמך קשר ";
                    //   message += "http://localhost:56996/api/Book/testString";
                    // message += "<br/>  <button> <a href=" + "http://localhost:56996/api/Book/testString" + "> אשר</a> </button>";
                    //נשלח מייל למשאיל
                    sendEmailFunc.sendEmailAsync(utL.email, utL.firstName + " " + utL.lastName, message, "בקשה להשאלת ספר " + bookName);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        public static string EditUser(User u)
        {
            UsersTable ut = new UsersTable()
            {
                id        = u.id,
                address   = u.address,
                birthDate = u.birthDate,
                //cityCode = u.cityCode.Code,
                email        = u.email,
                firstName    = u.firstName,
                genderId     = u.genderId.Code,
                houseNumber  = u.houseNumber,
                lastName     = u.lastName,
                neighborhood = u.neighborhood,
                password     = u.password,
                phone        = u.phone
            };

            if (u.cityCode.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.CitiesTableName, u.cityCode.Desc) != null)
                {
                    ut.cityCode = LookupBL.getLookupByName(Constants.CitiesTableName, u.cityCode.Desc).Code;
                }
                else
                {
                    ut.CityTable = new CityTable()
                    {
                        name = u.cityCode.Desc
                    }
                };
            }
            else
            {
                ut.cityCode = u.cityCode.Code;
            }

            string result = UserData.EditUser(ut);

            BooksLibraryDAL.LookupData.refreshLookups();
            return(result);
        }
Ejemplo n.º 8
0
        public static bool rejectBorrow(int idBorrow)
        {
            bool res = LenderData.rejectBorrow(idBorrow);

            if (res == true)
            {
                LendsTable lendTable = LenderData.getLendsByIdBorrow(idBorrow);
                //השואל
                UsersTable borrow = UserData.getUserById(lendTable.borrowerId);
                BooksTable bt     = BooksData.getBookById(lendTable.bookId);
                //המשאיל
                //   UsersTable ut = bt.UsersTable;
                string bookName = LookupBL.getLookupByCode(Constants.BooksNameTableName, bt.nameId).Desc;
                string message  = "מצטערים הספר " + bookName + " שביקשת  לא אושר על ידי בעל הספר באפשרותך לחפש ספר אחר במאגר הספרים שלנו  : ";
                //הצליח לשנות לאשר


                sendEmailFunc.sendEmailAsync(borrow.email, borrow.firstName + " " + borrow.lastName, message, "הודעה בדבר בקשה להשאלת ספר");
            }
            return(false);
        }
Ejemplo n.º 9
0
        public static int InsertBook(Books b)
        {
            BooksTable bt = new BooksTable();

            bt.numberOfViewers = 0;
            //אם הכנסת מחבר -
            if (b.autherId.Code == 0)
            {
                //בדוק האם קיים כזה מחבר
                if (LookupBL.getLookupByName(Constants.AutherTableName, b.autherId.Desc) != null)
                {//אם כן חבר בקשרי גומלין
                    bt.autherId = LookupBL.getLookupByName(Constants.AutherTableName, b.autherId.Desc).Code;
                }
                else
                {//אם לא צור חדש
                    bt.AutherTable = new AutherTable()
                    {
                        name = b.autherId.Desc
                    };
                }
            }
            else
            {
                bt.autherId = b.autherId.Code;
            }
            if (b.categoryId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.BooksCategoryTableName, b.categoryId.Desc) != null)
                {
                    bt.categoryId = LookupBL.getLookupByName(Constants.BooksCategoryTableName, b.categoryId.Desc).Code;
                }
                else
                {
                    bt.BooksCategriesTable = new BooksCategriesTable()
                    {
                        name = b.categoryId.Desc
                    };
                }
            }
            else
            {
                bt.categoryId = b.categoryId.Code;
            }
            bt.description = b.description;
            bt.isBorrowed  = false;
            bt.lenderId    = b.lenderId;
            if (b.nameId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.BooksNameTableName, b.nameId.Desc) != null)
                {
                    bt.nameId = LookupBL.getLookupByName(Constants.BooksNameTableName, b.nameId.Desc).Code;
                }
                else
                {
                    bt.BooksNameTable = new BooksNameTable()
                    {
                        name = b.nameId.Desc
                    };
                }
            }
            else
            {
                bt.nameId = b.nameId.Code;
            }

            bt.numOfPages = b.numOfPages;
            if (b.publishingId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.PuplishingTableName, b.publishingId.Desc) != null)
                {
                    bt.publishingId = LookupBL.getLookupByName(Constants.PuplishingTableName, b.publishingId.Desc).Code;
                }
                else
                {
                    bt.PublishingTable = new PublishingTable()
                    {
                        name = b.publishingId.Desc
                    };
                }
            }
            else
            {
                bt.publishingId = b.publishingId.Code;
            }
            int result = BooksData.InsertBook(bt);

            //var httpRequest = HttpContext.Current.Request;
            //if (httpRequest.Files.Count > 0)
            //{
            //    foreach (string file in httpRequest.Files)
            //    {
            //        var postedFile = httpRequest.Files[file];
            //        var filePath = HttpContext.Current.Server.MapPath("~/Images/picBook" + result);
            //        postedFile.SaveAs(filePath);
            //    }
            //}
            BooksLibraryDAL.LookupData.refreshLookups();
            return(result);
        }
Ejemplo n.º 10
0
        public static void editBook(Books b)
        {
            BooksTable bt = new BooksTable();

            bt.id = b.id;
            if (b.autherId.Code == 0)
            {
                //בדוק האם קיים כזה מחבר
                if (LookupBL.getLookupByName(Constants.AutherTableName, b.autherId.Desc) != null)
                {//אם כן חבר בקשרי גומלין
                    bt.autherId = LookupBL.getLookupByName(Constants.AutherTableName, b.autherId.Desc).Code;
                }
                else
                {//אם לא צור חדש
                    bt.AutherTable = new AutherTable()
                    {
                        name = b.autherId.Desc
                    };
                }
            }
            else
            {
                bt.autherId = b.autherId.Code;
            }
            if (b.categoryId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.BooksCategoryTableName, b.categoryId.Desc) != null)
                {
                    bt.categoryId = LookupBL.getLookupByName(Constants.BooksCategoryTableName, b.categoryId.Desc).Code;
                }
                else
                {
                    bt.BooksCategriesTable = new BooksCategriesTable()
                    {
                        name = b.categoryId.Desc
                    };
                }
            }
            else
            {
                bt.categoryId = b.categoryId.Code;
            }

            bt.description = b.description;
            bt.isBorrowed  = false;
            bt.lenderId    = 1;
            if (b.nameId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.BooksNameTableName, b.nameId.Desc) != null)
                {
                    bt.nameId = LookupBL.getLookupByName(Constants.BooksNameTableName, b.nameId.Desc).Code;
                }
                else
                {
                    bt.BooksNameTable = new BooksNameTable()
                    {
                        name = b.nameId.Desc
                    };
                }
            }
            else
            {
                bt.nameId = b.nameId.Code;
            }

            bt.numOfPages = b.numOfPages;
            if (b.publishingId.Code == 0)
            {
                if (LookupBL.getLookupByName(Constants.PuplishingTableName, b.publishingId.Desc) != null)
                {
                    bt.publishingId = LookupBL.getLookupByName(Constants.PuplishingTableName, b.publishingId.Desc).Code;
                }
                else
                {
                    bt.PublishingTable = new PublishingTable()
                    {
                        name = b.publishingId.Desc
                    };
                }
            }
            else
            {
                bt.publishingId = b.publishingId.Code;
            }


            BooksData.editBook(bt);
            BooksLibraryDAL.LookupData.refreshLookups();
            return;
        }
Ejemplo n.º 11
0
        //mv 05-03-2019
        public static bool returnBook(int idLender)
        {
            bool res = LenderData.returnBook(idLender);

            if (res == true)
            {
                LendsTable lending = LenderData.getLendsByIdBorrow(idLender);
                List <waitingForAbookTable> listWaiting = new List <waitingForAbookTable>();
                listWaiting = LenderData.GetAllWaitingForBook(lending.bookId);
                if (listWaiting.Count > 0)
                {
                    foreach (var item in listWaiting)
                    {
                        try
                        {
                            UsersTable u = UserData.getUserById(item.userCode);
                            if (u != null)
                            {
                                string messageTo = "";

                                string bookNameToMail = LookupBL.getLookupByCode(Constants.BooksNameTableName, BooksData.getBookById(lending.bookId).nameId).Desc;
                                messageTo += " הספר " + bookNameToMail + " הפך להיות זמין במערכת הנך יכול להיכנס לאתר ולשאול את הספר ";
                                sendEmailFunc.sendEmailAsync(u.email, u.firstName + " " + u.lastName, messageTo, "הודעת מערכת");
                                LenderData.removeWaitingToBookByIdWaiting(item);
                            }
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    }
                }


                /*
                 * LendsTable lendTable = LenderData.getLendsByIdBorrow(lending.bookId);
                 * //השואל
                 * UsersTable borrow = UserData.getUserById(lendTable.borrowerId);//השואל
                 * BooksTable bt = BooksData.getBookById(lendTable.bookId);
                 * //המשאיל
                 * UsersTable ut = UserData.getUserById(bt.lenderId);// המשאיל
                 * string bookName = LookupBL.getLookupByCode(Constants.BooksNameTableName, bt.nameId).Desc;
                 * string message = "התקבלה בקשה להחזרת הספר " + bookName;
                 * message += " פרטי בעל הספר ליצירת קשר  : ";
                 * message += ut.firstName + " " + ut.lastName + ", ";
                 * message += "טלפון: " + ut.phone + " מייל " + ut.email;
                 * //הצליח לשנות לאשר
                 * //לשוח מייל לשואל עם הפרטים
                 * // sendEmailFunc.sendEmailAsync(borrow.email, borrow.firstName + " " + borrow.lastName, message, "אישור החזרת ספר " + bookName);
                 *
                 * //שליחת מייל לבעלי הספר שרוצים להחזיר את הספר שלו
                 * message = "התקבלה בקשה להחזרת הספר " + bookName;
                 * message += " פרטי השואל ליצירת קשר  : ";
                 * message += borrow.firstName + " " + borrow.lastName + ", ";
                 * message += "טלפון: " + borrow.phone + " מייל " + borrow.email;
                 *
                 * //   sendEmailFunc.sendEmailAsync(ut.email, ut.firstName + " " + ut.lastName, message, "אישור החזרת ספר " + bookName);
                 */
            }
            return(res);
        }