public JsonResult AllBooks() { var books = BooksData.GetAll() .AsQueryable().Select(BookViewModel.FromBook); return(this.Json(books, JsonRequestBehavior.AllowGet)); }
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); }
/// <summary> /// Add book implementation /// </summary> /// <param name="data">Model BooksData that is receiving</param> /// <returns></returns> internal async Task <ResultsResponse> AddBookAction(BooksData data) { return(await Task.Run(() => { if (data.Title == null && data.Author == null) { return new ResultsResponse { Result = false, Message = "Complete all fields correct." } } ; try { using (var db = new StoreContext()) { var category = db.Categories.FirstOrDefault(m => m.Name == data.Category); var author = db.Authors.FirstOrDefault(m => m.Name == data.Author); var bookFind = db.Books.Where(m => m.Title == data.Title && m.AuthorId == author.AuthorId).FirstOrDefault(); if (bookFind == null) { var book = new Books { Title = data.Title, CategoryId = category.CategoryId, AuthorId = author.AuthorId, Publisher = data.Publisher, Description = data.Description, Price = data.Price, ImageSrc1 = data.ImageSrc1 }; db.Books.Add(book); db.SaveChanges(); return new ResultsResponse { Result = true, Message = "The book was added successfully." }; } else { return new ResultsResponse { Result = false, Message = "The book already exists." } }; } } catch (Exception e) { return new ResultsResponse { Result = false, Message = e.Message }; } })); }
public ActionResult Index() { var data = BooksData .GetAll() .AsQueryable() .Select(BookViewModel.FromBook) .ToList(); return(this.View(data)); }
public ActionResult Search(string query) { var result = BooksData .GetAll() .AsQueryable() .Where(book => book.Title.ToLower().Contains(query.ToLower())) .Select(BookViewModel.FromBook) .ToList(); return(this.PartialView("_BookResult", result)); }
public static void addBookToMybasket(MyBasketOfBooksModels obj) { MyBasketOfBooks bas = new MyBasketOfBooks() { idBook = obj.idBook, idUser = obj.idUser }; BooksData.addBookToMybasket(bas); return; }
public static Books getBookById(int id) {//שליפה -מחזיר אוביקט ממודל של אנטיטי BooksTable dbBook = BooksData.getBookById(id); //המרה מודל האנטיטי למודל משכבת BE Books b = CastBookTableToBook(dbBook); if (b != null) { return(b); } return(null); }
public static void rateBook(int idB, string desc, int rate) { Books b = new Books(); b = getBookById(idB); RatingTable RateB = new RatingTable(); RateB.bookId = b.id; // RateB.borrowerId = b.lenderId; RateB.desk = desc; RateB.rating = rate; RateB.dateInsert = DateTime.Now; BooksData.rateBook(RateB); }
public async Task AddBookTest() { var book = new BooksData { Title = "Designed for Digital4", Category = "Tech", Author = "Jeanne W. Ross", Publisher = "X", Price = 100 }; var result = await _controller.AddBook(book); Assert.IsTrue(result.Result); }
public static List <BookToList> Serch(string name, int?categoryIdSearch, string autherToSerch, string publishingToSerch, int?cityCode) { List <BooksTable> booksDB = BooksData.Serch(name, categoryIdSearch, autherToSerch, publishingToSerch, cityCode); List <BookToList> resBooks = new List <BookToList>(); foreach (var item in booksDB) { BookToList b = CastBookTableToBookLIST(item); if (b != null) { resBooks.Add(b); } } return(resBooks); }
public static List <BookToList> GetAllBook() { List <BooksTable> booksDB = BooksData.getAllBooks(); List <BookToList> resBooks = new List <BookToList>(); foreach (var item in booksDB) { BookToList b = CastBookTableToBookLIST(item); if (b != null) { resBooks.Add(b); } } return(resBooks); }
public static List <Books> getAllMyBasket(int idU) { List <BooksTable> MyBookTableList = BooksData.getAllMyBasket(idU); List <Books> MyBooksList = new List <Books>(); foreach (var item in MyBookTableList) { Books b = CastBookTableToBook(item); if (b != null) { MyBooksList.Add(b); } } return(MyBooksList); }
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 ActionResult ContentById(int id) { if (!Request.IsAjaxRequest()) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(this.Content("This action can be invoke only by AJAX call")); } var book = BooksData.GetAll().FirstOrDefault(x => x.Id == id); if (book == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(this.Content("Book not found")); } return(this.Content(book.Content)); }
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 JsonResult AllBooks() { var books = BooksData.GetAll() .AsQueryable().Select(TitledBookViewModel.FromBook); var client = new WebClient(); var quoteAsText = client.DownloadString("http://nvp-playground.azurewebsites.net/api/quotes/random/txt"); var quoteLines = quoteAsText.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var quote = new Quote() { Text = quoteLines[0], Author = quoteLines[1] }; return(this.Json(quote, JsonRequestBehavior.AllowGet)); }
public JsonResult AllBooks() { var books = BooksData.GetAll() .AsQueryable().Select(TitledBookViewModel.FromBook); var client = new WebClient(); var quoteAsText = client.DownloadString(QuotesUrl); var quoteLines = quoteAsText.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var quote = new Quote() { Text = quoteLines[0].Replace('’', '*'), Author = quoteLines[1] }; return(this.Json(quote, JsonRequestBehavior.AllowGet)); }
public static List <Books> getAllUsersBooksByIDU(int idu) { List <BooksTable> MyBookTableList = BooksData.getAllUsersBooksByIDU(idu); List <Books> MyBooksList = new List <Books>(); if (MyBookTableList != null) { foreach (var item in MyBookTableList) { Books b = CastBookTableToBook(item); if (b != null) { MyBooksList.Add(b); } } return(MyBooksList); } return(null); }
public ActionResult Index(string searchTerm, int pageNumber = 1) { if (!string.IsNullOrWhiteSpace(searchTerm)) { TempData["SearchTerm"] = searchTerm; if (pageNumber == 1) { BooksData booksData = null; Books books = new Books(); var client = new RestClient("http://it-ebooks-api.info/v1/"); var request = new RestRequest(); request.Resource = "/search/" + searchTerm; var response = client.Execute(request) as RestResponse; if (response != null && ((response.StatusCode == HttpStatusCode.OK) && (response.ResponseStatus == ResponseStatus.Completed))) { booksData = JsonConvert.DeserializeObject <BooksData>(response.Content); books.BookData = booksData; TempData["Books"] = booksData; return(View(books)); } } else { TempData["SearchTerm"] = searchTerm; BooksData booksData = null; Books books = new Books(); var client = new RestClient("http://it-ebooks-api.info/v1/"); var request = new RestRequest(); request.Resource = "/search/" + searchTerm + "/page/" + pageNumber.ToString(); var response = client.Execute(request) as RestResponse; if (response != null && ((response.StatusCode == HttpStatusCode.OK) && (response.ResponseStatus == ResponseStatus.Completed))) { booksData = JsonConvert.DeserializeObject <BooksData>(response.Content); books.BookData = booksData; TempData["Books"] = booksData; return(View(books)); } } } return(View()); }
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); }
/// <summary> /// Get all books implementation /// </summary> /// <returns></returns> internal async Task <List <BooksData> > GetBooksAction() { return(await Task.Run(() => { try { using (var db = new StoreContext()) { var list = new List <BooksData>(); var result = db.Books.Join(db.Categories, t => t.CategoryId, c => c.CategoryId, (t, c) => new { t, c }) .Join(db.Authors, d => d.t.CategoryId, c => c.AuthorId, (d, c) => new{ d, c }).ToList(); foreach (var item in result) { var book = new BooksData { BookId = item.d.t.BookId, Title = item.d.t.Title, Category = item.d.c.Name, Author = item.c.Name, Description = item.d.t.Description, ImageSrc1 = item.d.t.ImageSrc1, Price = item.d.t.Price, Publisher = item.d.t.Publisher }; list.Add(book); } return list; } } catch { //Logging method return null; } })); }
public BooksController() { this.books = new BooksData(); }
public static void deleteBookFromMyBuskate(int idB, int idU) { BooksData.deleteBookFromMyBuskate(idB, idU); }
public static void saveImageName(int idBook, string nameBook) { BooksData.saveImageName(idBook, nameBook); }
public static void PromoteNumberOfViewers(int idBook) { BooksData.PromoteNumberOfViewers(idBook); }
public static void deleteBook(int idB) { BooksData.deleteBook(idB); }
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 IActionResult GetBooks() { return(Ok(BooksData.GetBooksAsList())); }
public async Task <ResultsResponse> AddBook(BooksData data) { return(await user.AddBook(data)); }