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); }
public ActionResult AddNewBook(BooksTable newb) { var book = db.BooksTable.FirstOrDefault(s => s.BookName == newb.BookName && s.WritersNameSurname == newb.WritersNameSurname); if (book == null) { BooksTable book1 = new BooksTable() { BookName = newb.BookName, BookPrice = newb.BookPrice, BookPhoto = newb.BookPhoto, WritersNameSurname = newb.WritersNameSurname }; db.BooksTable.Add(book1); db.SaveChanges(); } else { ViewBag.BookError = "The book which you entered has already exist..."; } return(View()); }
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); } }
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); } }
public bool DiscountOne(User user, string isbn, int pricePercentage) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.DiscountOne(isbn, pricePercentage) == 1); } return(false); }
public bool DiscountByAuthor(User user, string author, int pricePercentage) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.DiscountByAuthor(author, pricePercentage) == 1); } return(false); }
public bool DiscountAll(User user, int pricePercentage) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.DiscountAll(pricePercentage) == 1); } return(false); }
public BookModel ListByIsbn(User user, string isbn) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.ListByISBN(isbn)); } return(null); }
public bool Update(User user, BookModel bookModel, int price, int instock) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.Update(bookModel, price, instock) == 1); } return(false); }
public List <BookModel> ListAll(User user) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); return(booksTable.Select()); } return(null); }
public bool Delete(User user, string isbn) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); booksTable.Delete(booksTable.ListByISBN(isbn)); } return(false); }
public static Books getBookById(int id) {//שליפה -מחזיר אוביקט ממודל של אנטיטי BooksTable dbBook = BooksData.getBookById(id); //המרה מודל האנטיטי למודל משכבת BE Books b = CastBookTableToBook(dbBook); if (b != null) { return(b); } return(null); }
public bool Insert(User user, string isbn, string title, string author, string publicationDate, int price, int instock) { if (HasGuid(user)) { BooksTable booksTable = new BooksTable(); BookModel book = new BookModel(); book.Isbn = isbn; book.Title = title; book.Author = author; book.PublicationDate = publicationDate; book.Price = price; book.Instock = instock; return(booksTable.Insert(book) == 1); } return(false); }
public static Statistics Fullstatistics(int id) { BooksTable dbBook = BooksData.getBookAndOtherDetailesToStatisckById(id); Statistics statistic = new Statistics(); statistic.Comments = new List <Comment>(); foreach (var item in dbBook.RatingTable.OrderByDescending(r => r.dateInsert).ToList()) { if (item.desk != null) { Comment c = new Comment(); c.comment = item.desk; if (item.dateInsert != null) { c.date = (DateTime)item.dateInsert; } statistic.Comments.Add(c); } } statistic.numberOfViewers = dbBook.numberOfViewers; statistic.numberOfLendings = dbBook.LendsTable.Where(l => l.statusCode == 2 || l.statusCode == 4).Count(); int[] WomenAndMen = BooksData.numWomenRead(dbBook.id); if (WomenAndMen != null) { statistic.numberOfwomen = WomenAndMen[0]; statistic.numberOfMen = WomenAndMen[1]; } statistic.numberOfLikeIt = dbBook.MyBasketOfBooks.Count(); int count = 0, sum = 0; for (int i = 0; i < 5; i++) { statistic.rstingList[i] = dbBook.RatingTable.Where(r => r.rating == i + 1).Count(); if (statistic.rstingList[i] != 0) { count += statistic.rstingList[i]; sum += ((i + 1) * statistic.rstingList[i]); } } if (count != 0) { statistic.averageRating = sum / count; } return(statistic); }
public static Books getBookAndOtherDetailesToStatisckById(int id) { BooksTable dbBook = BooksData.getBookAndOtherDetailesToStatisckById(id); //פונקצית המרת הנתונים למודל שיוכר בצד לקוח Books bookModel = CastBookTableToBook(dbBook); if (bookModel != null) { //שליפת הסטטיסטיקות של הספר // bookModel.Statistics = Fullstatistics(dbBook); //שליפת הדרוגים והתגובות על הספר // bookModel.ratingList = GetAllRatingByIdBook(dbBook.id); return(bookModel); } return(null); }
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); }
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); }
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); }
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; }