public IActionResult Cart() { List <int> ints = this._sessionHandler.GetBooksFromCart(HttpContext); BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); foreach (int i in ints) { Book book = this._bookContainer.GetBookById(i); if (book.Name != null) { BookModel temp = new BookModel(); temp.Id = book.Id; temp.Name = book.Name; temp.Price = book.Price; temp.QualityRating = book.QualityRating; bivm.Books.Add(temp); } } return(View(bivm)); }
public async Task UpdateBook(BookIndexViewModel model) { if (model == null) { throw new NullReferenceException("Book not found."); } if (this.bookRepo.All().Any(b => b.Title == model.Title && b.Id != model.Id)) { throw new InvalidOperationException("Book with such title already exists."); } if (this.bookRepo.All().Any(b => b.DownloadUrl == model.DownloadUrl && b.Id != model.Id)) { throw new InvalidOperationException("Book with such download url already exists."); } var book = this.mapper.Map <BookIndexViewModel, Book>(model); this.bookRepo.Update(book); try { await this.bookRepo.SaveChangesAsync(); } catch (Exception e) { this.logger.LogDebug(e.Message); throw new InvalidOperationException("Sorry, an error occurred while trying to edit a book."); } }
// GET: Books public async Task <ActionResult> Index(string userId) { var currentUserId = GetCurrentUserId(); // If no user supplied, look at my bookshelf if (userId == null) { userId = currentUserId; } // If not my bookshelf, check to see I'm permitted to view it--am I friends with the target user? if (userId != currentUserId) { var friendship = await repo.GetFriendshipBetweenUserIdsAsync(currentUserId, userId); if (friendship == null || !friendship.RequestApproved.HasValue) { throw new HttpException((int)HttpStatusCode.Forbidden, "You must be friends to view that user's books"); } } var model = new BookIndexViewModel { Books = await repo.GetBooksByOwnerIdAsync(userId), User = await repo.GetUserNameByIdAsync(userId) }; return(View(model)); }
public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); foreach (Book book in BookContainer.GetNewestBooks(8)) { BookModel temp = new BookModel(); temp.Id = book.Id; temp.Name = book.Name; temp.Price = book.Price; temp.QualityRating = book.QualityRating; bivm.Books.Add(temp); } return(View(bivm)); }
public IActionResult Index() { var model = new BookIndexViewModel() { Books = bookData.GetBooks() }; return(View(model)); }
public IActionResult Index() { var model = new BookIndexViewModel { Books = _bookData.GetAll(), }; return(View(model)); }
private BookIndexViewModel GetBookIndexViewModel() { BookIndexViewModel bookIndexViewModel = new BookIndexViewModel(); var bookViewModels = GetBooks(); bookIndexViewModel.BookViewModels = bookViewModels; bookIndexViewModel.TotalBooksOnOffer = bookViewModels.Count(); return(bookIndexViewModel); }
public static BookIndexViewModel GetBookIndexModel () { if (BookIndexModel == null ) { BookIndexModel = new BookIndexViewModel(null); } return BookIndexModel; }
public ActionResult Index(BookIndexViewModel search, int?page, int?itemsPerPage, string sortField = "", SortOrder sortOrder = SortOrder.Ascending) { using (var wrapper = new SessionWrapper()) { using (ITransaction transaction = wrapper.Session.BeginTransaction()) { BookIndexViewModel responseViewModel = search; if (String.IsNullOrEmpty(responseViewModel.SentFromPost)) { responseViewModel.ItemsPerPage = itemsPerPage ?? DEFAULT_ITEMS_PER_PAGE_VALUE; responseViewModel.Order = sortOrder; if (!String.IsNullOrEmpty(sortField)) { responseViewModel.SortField = sortField; } } IEnumerable <Book> sortedBooks; if (sortOrder == SortOrder.Descending) { sortedBooks = wrapper.Session.CreateCriteria <Book>() .AddOrder(Order.Desc(responseViewModel.SortField)) .List <Book>(); } else { sortedBooks = wrapper.Session.CreateCriteria <Book>() .AddOrder(Order.Asc(responseViewModel.SortField)) .List <Book>(); } int pageNumber = page ?? 1; IEnumerable <Book> filteredBooks; if (!string.IsNullOrEmpty(responseViewModel.SearchName)) { filteredBooks = sortedBooks.Where(o => o.Name.Contains(responseViewModel.SearchName)); responseViewModel.Books = filteredBooks.ToPagedList(pageNumber, responseViewModel.ItemsPerPage); } else { responseViewModel.Books = sortedBooks.ToPagedList(pageNumber, responseViewModel.ItemsPerPage); } return(View(responseViewModel)); } } }
public IActionResult Index(BookIndexViewModel model) { if (model == null) { model = new BookIndexViewModel(); } //model.PagingData.Records = _mapper.Map<List<Book>, List<BookDto>>(_bookRepository.GetDBSet().ToList()); //model.PagingData.TotalRecords = _bookRepository.GetDBSet().Count(); return(View(model)); }
public ActionResult Index() { List <Book> books = _db.Books.Include(book => book.Authors).ThenInclude(entry => entry.Author).ToList(); List <int> bookIds = books.Select(book => book.BookId).ToList(); List <Copy> copies = _db.Copies.Where(copy => bookIds.Contains(copy.BookId)).ToList(); ViewBag.BookBag = Checkout.BookBag; BookIndexViewModel model = new BookIndexViewModel() { Books = books, Copies = copies }; return(View(model)); }
public async Task UpdateBook_WithNullData_ShouldThrow() { //Arange var db = this.SetDb(); await this.SeedBook(db); var repo = new Repository <Book>(db); var bookService = new BookService(repo, this.Mapper, null); BookIndexViewModel model = null; //Act //Assert await Assert.ThrowsAsync <NullReferenceException>(async() => await bookService.UpdateBook(this.Mapper.Map <BookIndexViewModel>(model))); }
public async Task DeleteBook_WithNullModel_ShouldReturnEmptyRepo() { //Assert var db = this.SetDb(); await this.SeedBook(db); var repo = new Repository <Book>(db); var service = new BookService(repo, this.Mapper, null); BookIndexViewModel model = null; //Act //Assert await Assert.ThrowsAsync <NullReferenceException>(async() => await service.DeleteBook(model)); }
public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); foreach (Book book in BookContainer.GetAllBooks()) { // FIXME: Dit moet beter kunnen. BookModel temp = new BookModel(); temp.Id = book.Id; temp.User = new UserModel(); temp.User.Id = book.User.Id; temp.User.FirstName = book.User.FirstName; temp.User.Insertion = book.User.Insertion; temp.User.LastName = book.User.LastName; temp.User.Email = book.User.Email; temp.Course = new CourseModel(); temp.Course.Id = book.Course.Id; temp.Course.Name = book.Course.Name; temp.Sector = new SectorModel(); temp.Sector.Id = book.Sector.Id; temp.Sector.Name = book.Sector.Name; temp.Name = book.Name; temp.Price = book.Price; temp.QualityRating = book.QualityRating; bivm.Books.Add(temp); } return(View(bivm)); }
public IActionResult Search(string name) { if (!this._middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); BookConverter bookConverter = new BookConverter(); foreach (Book book in this._bookContainer.GetBookByName(name)) { bivm.Books.Add(bookConverter.ConvertBookToBookModel(book)); } return(View(bivm)); }
public IActionResult Index() { if (!this._middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); BookConverter bookConverter = new BookConverter(); foreach (Book book in this._bookContainer.GetBooksByUserID(this._sessionHandler.GetUserID(HttpContext))) { bivm.Books.Add(bookConverter.ConvertBookToBookModel(book)); } return(View(bivm)); }
public async Task <IActionResult> Index() { var httpClient = await _accessHttpClient.GetClient(); var response = await httpClient.GetAsync("api/books").ConfigureAwait(false); if (response.IsSuccessStatusCode) { var bookAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var bookIndexViewModel = new BookIndexViewModel(JsonConvert.DeserializeObject <IList <Book> >(bookAsString).ToList()); return(View(bookIndexViewModel)); } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { return(RedirectToAction("AccessDenied", "Authorization")); } throw new Exception($"An error occure while calling the API: { response.ReasonPhrase }"); }
public async Task DeleteBook(BookIndexViewModel model) { if (model == null) { throw new NullReferenceException("Book not found."); } var book = this.mapper.Map <BookIndexViewModel, Book>(model); this.bookRepo.Delete(book); try { await this.bookRepo.SaveChangesAsync(); } catch (Exception e) { this.logger.LogDebug(e.Message); throw new InvalidOperationException("Sorry, an error occurred while trying to delete book."); } }
public async Task <ActionResult> Index() { if (!await _authorizationService.AuthorizeAsync(User, Permissions.BookAccess)) { return(Unauthorized()); } var bookQuery = _session.Query <BookModel, BookIndex>(); var model = new BookIndexViewModel(); foreach (var book in await bookQuery.ListAsync()) { model.Books.Add(new BookModelEntry { Id = book.Id, Title = book.Title, Author = book.Author, CoverPhotoUrl = book.CoverPhotoUrl, Description = book.Description }); } return(View(model)); }
public async Task<IActionResult> DeleteBook(BookIndexViewModel model) { if (!ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(p => p.Errors).Select(e => e.ErrorMessage).ToList(); var errorModel = this.errorService.GetErrorModel(errors); return View("Error", errorModel); } try { await this.bookService.DeleteBook(model); } catch (Exception e) { ViewData["Errors"] = e.Message; return this.View("Error"); } return RedirectToAction("Index"); }
public ActionResult GetBooksData(string genre, string author, string publisher, string search, string sortBy, int?page) { //instantiate a new view model BookIndexViewModel viewModel = new BookIndexViewModel(); //select the books var books = db.Books.Include(b => b.Author).Include(b => b.Genre).Include(b => b.Publisher); //To search from navbar at any given page to book index //also perform the search and save the searchstring to the viewmodel if (!String.IsNullOrEmpty(search)) { books = books.Where(p => p.Title.Contains(search) || p.Author.FullName.Contains(search) || p.Publisher.Name.Contains(search) || p.Genre.Title.Contains(search)); viewModel.Search = search; viewModel.Genre = genre; viewModel.Author = author; viewModel.Publisher = publisher; } //group search results into genres and count how many items in ech genre viewModel.GenresWithCount = from matchingBooks in books where matchingBooks.GenreId != null group matchingBooks by matchingBooks.Genre.Title into genreGroup select new GenreWithCount() { GenreTitle = genreGroup.Key, BookCount = genreGroup.Count() }; viewModel.AuthorsWithCount = from matchingBooks in books where matchingBooks.AuthorId != null group matchingBooks by matchingBooks.Author.FullName into authorGroup select new AuthorWithCount() { AuthorFullName = authorGroup.Key, BookCount = authorGroup.Count() }; viewModel.PublishersWithCount = from matchingBooks in books where matchingBooks.PublisherId != null group matchingBooks by matchingBooks.Publisher.Name into publisherGroup select new PublisherWithCount() { PublisherName = publisherGroup.Key, BookCount = publisherGroup.Count() }; // (1) To navigate from genre index to book index //TO DO (?) //Apply the same to Author, Publisher (?) if (!String.IsNullOrEmpty(genre) && String.IsNullOrEmpty(author) && String.IsNullOrEmpty(publisher)) { books = books.Where(p => p.Genre.Title == genre); } if (!String.IsNullOrEmpty(author) && String.IsNullOrEmpty(genre) && String.IsNullOrEmpty(publisher)) { books = books.Where(p => p.Author.FullName == author); } if (!String.IsNullOrEmpty(publisher) && String.IsNullOrEmpty(genre) && String.IsNullOrEmpty(author)) { books = books.Where(p => p.Publisher.Name == publisher); } //sorting the results switch (sortBy) { case "author_ascending": books = books.OrderBy(n => n.Author.FullName); break; case "publisher_ascending": books = books.OrderBy(n => n.Publisher.Name); break; case "price_ascending": books = books.OrderBy(n => n.Price); break; case "price_descending": books = books.OrderByDescending(n => n.Price); break; case "release_date_ascending": books = books.OrderBy(n => n.ReleaseDate); break; case "release_date_descending": books = books.OrderByDescending(n => n.ReleaseDate); break; default: books = books.OrderBy(n => n.Author.FullName); break; } //const int PageItems = 3; int currentPage = (page ?? 1); viewModel.Books = books.ToPagedList(currentPage, Constants.PageItems); viewModel.SortBy = sortBy; // viewModel.Sorts = new Dictionary <string, string> { { "Author", "author_ascending" }, { "Publisher", "publisher_ascending" }, { "Lowest Price", "price_ascending" }, { "Highest Price", "price_descending" }, { "Oldest Release", "release_date_ascending" }, { "Newest Release", "release_date_descending" } }; return(PartialView("_LiveUpdate", viewModel)); }
public ActionResult Edit(SummaryEditViewModel summ, List <string> Sent, List <bool> Selected, bool undo = false) { int linesNoOf, sentencesNoOf, paragraphsNoOf, paragraphPtr, newNoOfParagraphs; string p; List <string> lines, sentences, paragrphs, newParagraphs; Paragraphs paragraphs; List <int> sentenceInParagraph; List <bool> selectedSentences; IEnumerable <Node> nodes; IEnumerable <Picture> pictures; bool haspict = false; bool hasnofigpara = true; bool hasnotabpara = true; bool itHasATableHeading = false; bool tableStarted = false; bool NodeIDOK = false; int listStartedAt = -1; int tableStartedAt = -1; sentenceInParagraph = new List <int>(); selectedSentences = new List <bool>(); paragrphs = new List <string>(); sentences = new List <string>(); lines = new List <string>(); newParagraphs = new List <string>(); paragraphs = new Paragraphs(); paragraphPtr = 0; paragraphs.TheText = summ.Summary.Summary1; for (int i = 0; i < summ.SentencesNoOf; i++) { if (summ.SentenceInParagraph[i] != paragraphPtr) { paragraphs.TheText += "\r\n"; paragraphPtr = summ.SentenceInParagraph[i]; } if (summ.SelectedSentences[i]) { paragraphs.TheText += summ.Sentences[i] + " "; } } paragraphs.NoOfChars = paragraphs.TheText.Length; paragraphs.Paragrphs(out paragraphsNoOf, ref paragrphs, out sentencesNoOf, ref sentences, ref sentenceInParagraph, out linesNoOf, ref lines, 0, false, true, true, false, true, false, true); summ.Summary.Summary1 = paragraphs.TheAlteredText; nodes = repository.Nodes.Where(n => n.NodeID == summ.Summary.NodeID); pictures = repository.Pictures.Where(pic => pic.NodeID == summ.Summary.NodeID); if (pictures.Count() > 0) { haspict = true; } newNoOfParagraphs = 0; for (int i = 0; i < paragraphsNoOf; i++) { p = paragrphs.ToArray()[i]; if (p.Length > 2) { if (p.Substring(0, 3).ToLower() == "fig") { hasnofigpara = false; } if (p.Substring(0, 3).ToLower() == "tab") { hasnotabpara = false; itHasATableHeading = true; tableStarted = false; } } if (p.Substring(0, 1) == "¤" || p.Substring(0, 1) == "¥" || p.IndexOf((Char)9) > 0) { if (p.Substring(0, 1) == "¤" || p.Substring(0, 1) == "¥") { tableStartedAt = -1; if (listStartedAt == -1) { listStartedAt = newNoOfParagraphs; newParagraphs.Add(""); newNoOfParagraphs++; } if (listStartedAt > -1) { newParagraphs[listStartedAt] += p; } } if (p.IndexOf((Char)9) > 0) { if (itHasATableHeading) { listStartedAt = -1; if (tableStartedAt == -1) { tableStarted = true; tableStartedAt = newNoOfParagraphs; newParagraphs.Add(""); newNoOfParagraphs++; } if (tableStartedAt > -1) { if (p.Substring(0, 1) == "§") { newParagraphs[tableStartedAt] += "£" + p.Substring(1); } else { newParagraphs[tableStartedAt] += "£" + p; } } } else { listStartedAt = -1; tableStartedAt = -1; if (p.Length > 2) { if (p != "§\r\n") { newNoOfParagraphs++; newParagraphs.Add(p); } } if (tableStarted) { itHasATableHeading = false; tableStarted = false; } } } } else { listStartedAt = -1; tableStartedAt = -1; if (p.Length > 2) { if (p != "§\r\n") { newNoOfParagraphs++; newParagraphs.Add(p); } } if (tableStarted) { itHasATableHeading = false; tableStarted = false; } } } BookIndexViewModel model = new BookIndexViewModel { Node = nodes.FirstOrDefault(), Summary = summ.Summary, SentencesNoOf = summ.SentencesNoOf, Sentences = summ.Sentences, SentenceInParagraph = summ.SentenceInParagraph, SelectedSentences = summ.SelectedSentences, Paragraphs = paragrphs, NoOfParagraphs = paragraphsNoOf, Paragraph = "", HasPicture = haspict, NoOfPictures = pictures.Count(), PicturePointer = 0, Pictures = pictures, PictureTitle = "", PictureFile = null, PictureFixed = false, HasSummary = false, HasChildren = false, NoOfChildren = 0, HasParent = false, HasNoFigPara = false, HasNoTabPara = false, ShowingDetails = true, ShowingSummary = false, SearchKey = "" }; if (ModelState.IsValid) { if (summ.Summary.SummaryID == 0) { //repository.Edit(summ.Summary); TempData["message"] = string.Format("Summary: {0} ... has been created for Node: {1}", summ.Summary.SummaryID, summ.Summary.NodeID); } else { //repository.Edit(summ.Summary); TempData["message"] = string.Format("Summary: {0} ... has been editted for Node: {1}", summ.Summary.SummaryID, summ.Summary.NodeID); } //return RedirectToAction("Index", "Book", new { NodeID = summ.Summary.NodeID }); return(View(model)); } else { // there is something wrong with the data values return(View(model)); } }
public ViewResult Edit(int NodeID) { int linesNoOf, sentencesNoOf, paragraphsNoOf, newNoOfParagraphs; string p; List <string> lines, sentences, paragrphs, para, newParagraphs; Paragraphs paragraphs; List <int> sentenceInParagraph; List <bool> selectedSentences; IEnumerable <Node> nodes; IEnumerable <Picture> pictures; bool haspict = false; bool hasnofigpara = true; bool hasnotabpara = true; bool itHasATableHeading = false; bool tableStarted = false; bool NodeIDOK = false; int listStartedAt = -1; int tableStartedAt = -1; sentenceInParagraph = new List <int>(); selectedSentences = new List <bool>(); paragrphs = new List <string>(); para = new List <string>(); newParagraphs = new List <string>(); sentences = new List <string>(); lines = new List <string>(); paragraphs = new Paragraphs(); Node node = repository.Nodes.Single(n => n.NodeID == NodeID); paragraphs.TheText = node.NodeText; paragraphs.NoOfChars = paragraphs.TheText.Length; paragraphs.Paragrphs(out paragraphsNoOf, ref paragrphs, out sentencesNoOf, ref sentences, ref sentenceInParagraph, out linesNoOf, ref lines, 0, false, true, true, false, true, false, true); for (int i = 0; i < sentencesNoOf; i++) { selectedSentences.Add(false); } para.Add(" "); Summary summary = new Summary(); summary.NodeID = NodeID; summary.Summary1 = node.Heading + ":- \r\n"; nodes = repository.Nodes.Where(n => n.NodeID == NodeID); pictures = repository.Pictures.Where(pic => pic.NodeID == NodeID); if (pictures.Count() > 0) { haspict = true; } newNoOfParagraphs = 0; for (int i = 0; i < paragraphsNoOf; i++) { p = paragrphs.ToArray()[i]; if (p.Length > 2) { if (p.Substring(0, 3).ToLower() == "fig") { hasnofigpara = false; } if (p.Substring(0, 3).ToLower() == "tab") { hasnotabpara = false; itHasATableHeading = true; tableStarted = false; } } if (p.Substring(0, 1) == "¤" || p.Substring(0, 1) == "¥" || p.IndexOf((Char)9) > 0) { if (p.Substring(0, 1) == "¤" || p.Substring(0, 1) == "¥") { tableStartedAt = -1; if (listStartedAt == -1) { listStartedAt = newNoOfParagraphs; newParagraphs.Add(""); newNoOfParagraphs++; } if (listStartedAt > -1) { newParagraphs[listStartedAt] += p; } } if (p.IndexOf((Char)9) > 0) { if (itHasATableHeading) { listStartedAt = -1; if (tableStartedAt == -1) { tableStarted = true; tableStartedAt = newNoOfParagraphs; newParagraphs.Add(""); newNoOfParagraphs++; } if (tableStartedAt > -1) { if (p.Substring(0, 1) == "§") { newParagraphs[tableStartedAt] += "£" + p.Substring(1); } else { newParagraphs[tableStartedAt] += "£" + p; } } } else { listStartedAt = -1; tableStartedAt = -1; if (p.Length > 2) { if (p != "§\r\n") { newNoOfParagraphs++; newParagraphs.Add(p); } } if (tableStarted) { itHasATableHeading = false; tableStarted = false; } } } } else { listStartedAt = -1; tableStartedAt = -1; if (p.Length > 2) { if (p != "§\r\n") { newNoOfParagraphs++; newParagraphs.Add(p); } } if (tableStarted) { itHasATableHeading = false; tableStarted = false; } } } BookIndexViewModel model = new BookIndexViewModel { Node = nodes.FirstOrDefault(), Summary = summary, SentencesNoOf = sentencesNoOf, Sentences = sentences, SentenceInParagraph = sentenceInParagraph, SelectedSentences = selectedSentences, Paragraphs = para, NoOfParagraphs = 1, Paragraph = "", HasPicture = haspict, NoOfPictures = pictures.Count(), PicturePointer = 0, Pictures = pictures, PictureTitle = "", PictureFile = null, PictureFixed = false, HasSummary = false, HasChildren = false, NoOfChildren = 0, HasParent = false, HasNoFigPara = false, HasNoTabPara = false, ShowingDetails = true, ShowingSummary = false, SearchKey = "" }; return(View(model)); }
public IActionResult Index(string title = "", int row = 2, int pager = 1) { string userid = User.FindFirstValue(ClaimTypes.NameIdentifier); string role = User.FindFirstValue(ClaimTypes.Role); var Row = new List <int> { 2, 5, 10, 15 }; ViewBag.item = new SelectList(Row, row); ViewBag.pageNumber = (pager - 1) * row + 1; title = String.IsNullOrEmpty(title) ? "" : title; string AuthersName = ""; List <BookIndexViewModel> viewModels = new List <BookIndexViewModel>(); var Books = (from b in _context.BookStors join p in _context.Publishers on b.PublisherID equals p.PublisherId join ab in _context.Auther_Books on b.BookId equals ab.BookId join au in _context.Authers on ab.AutherId equals au.AutherId where (b.Delete == false && b.Title.Contains(title.TrimStart().TrimEnd())) select new BookIndexViewModel { Title = b.Title, ISBN = b.ISBN, BookId = b.BookId, Price = b.Price, Stock = b.Stock, IsPublish = b.IsPublish, PublishDate = b.PublishDate, Publisher = p.PublisherName, Auther = au.Name + " " + au.LastName, }) .GroupBy(b => b.BookId).Select(g => new { g.Key, BookGroups = g }).ToList(); foreach (var item in Books) { AuthersName = ""; foreach (var group in item.BookGroups) { if (AuthersName == "") { AuthersName = group.Auther; } else { AuthersName = AuthersName + " - " + group.Auther; } } BookIndexViewModel VM = new BookIndexViewModel() { Auther = AuthersName, BookId = item.BookGroups.First().BookId, ISBN = item.BookGroups.First().ISBN, Title = item.BookGroups.First().Title, Price = item.BookGroups.First().Price, IsPublish = item.BookGroups.First().IsPublish, PublishDate = item.BookGroups.First().PublishDate, Publisher = item.BookGroups.First().Publisher, Stock = item.BookGroups.First().Stock, Image = item.BookGroups.First().Image, }; viewModels.Add(VM); } var PagingModel = PagingList.Create(viewModels, row, pager); PagingModel.RouteValue = new RouteValueDictionary { { "row", row } }; return(View(PagingModel)); }
public List <BookIndexViewModel> GetAllBooks(string title, string ISBN, string Language, string Publisher, string Author, string Translator, string Category) { string AuthersName = ""; string TranslatorName = ""; string CategoryName = ""; List <BookIndexViewModel> viewModels = new List <BookIndexViewModel>(); //var Books = (from u in _context.Author_Books.Include(b => b.Book).ThenInclude(p => p.Publisher) // .Include(a => a.Author) // join l in _context.Languages on u.Book.LanguageID equals l.LanguageID // join s in _context.Book_Translators on u.Book.BookID equals s.BookID into bt // from bts in bt.DefaultIfEmpty() // join t in _context.Translator on bts.TranslatorID equals t.TranslatorID into tr // from trl in tr.DefaultIfEmpty() // join r in _context.Book_Categories on u.Book.BookID equals r.BookID into bc // from bct in bc.DefaultIfEmpty() // join c in _context.Categories on bct.CategoryID equals c.CategoryID into cg // from cog in cg.DefaultIfEmpty() // where (u.Book.Delete == false && u.Book.Title.Contains(title.TrimStart().TrimEnd()) && u.Book.ISBN.Contains(ISBN.TrimStart().TrimEnd()) // && EF.Functions.Like(l.LanguageName, "%" + Language + "%") // && u.Book.Publisher.PublisherName.Contains(Publisher.TrimStart().TrimEnd())) //بعد از قرار دادن quey Filter قسمت u.Book.Delete == false && حذف گردید var Books = (from u in _context.Author_Books.Include(b => b.Book).ThenInclude(p => p.Publisher) .Include(a => a.Author) join l in _context.Languages on u.Book.LanguageID equals l.LanguageID join s in _context.Book_Translators on u.Book.BookID equals s.BookID into bt from bts in bt.DefaultIfEmpty() join t in _context.Translator on bts.TranslatorID equals t.TranslatorID into tr from trl in tr.DefaultIfEmpty() join r in _context.Book_Categories on u.Book.BookID equals r.BookID into bc from bct in bc.DefaultIfEmpty() join c in _context.Categories on bct.CategoryID equals c.CategoryID into cg from cog in cg.DefaultIfEmpty() where (u.Book.Title.Contains(title.TrimStart().TrimEnd()) && u.Book.ISBN.Contains(ISBN.TrimStart().TrimEnd()) && EF.Functions.Like(l.LanguageName, "%" + Language + "%") && u.Book.Publisher.PublisherName.Contains(Publisher.TrimStart().TrimEnd())) select new { Author = u.Author.FirstName + " " + u.Author.LastName, Translator = bts != null ? trl.Name + " " + trl.Family : "", Category = bct != null ? cog.CategoryName : "", l.LanguageName, u.Book.BookID, u.Book.ISBN, u.Book.Title, u.Book.Price, u.Book.IsPublish, u.Book.PublishDate, u.Book.Publisher.PublisherName, u.Book.Stock, }).Where(a => a.Author.Contains(Author) && a.Translator.Contains(Translator) && a.Category.Contains(Category)).GroupBy(b => b.BookID).Select(g => new { BookID = g.Key, BookGroups = g }).AsNoTracking().ToList(); foreach (var item in Books) { AuthersName = ""; foreach (var group in item.BookGroups.Select(a => a.Author).Distinct()) { if (AuthersName == "") { AuthersName = group; } else { AuthersName = AuthersName + " - " + group; } } foreach (var group in item.BookGroups.Select(a => a.Translator).Distinct()) { if (TranslatorName == "") { TranslatorName = group; } else { TranslatorName = TranslatorName + " - " + group; } } foreach (var group in item.BookGroups.Select(a => a.Category).Distinct()) { if (CategoryName == "") { CategoryName = group; } else { CategoryName = CategoryName + " - " + group; } } BookIndexViewModel VM = new BookIndexViewModel() { Author = AuthersName, BookID = item.BookID, ISBN = item.BookGroups.First().ISBN, Title = item.BookGroups.First().Title, Price = item.BookGroups.First().Price, IsPublish = item.BookGroups.First().IsPublish == true ? "منتشر شده" : "پیش نویس", PublishDate = item.BookGroups.First().PublishDate != null?_convertDate.ConvertMiladiToShamsi((DateTime)item.BookGroups.First().PublishDate, "dddd d MMMM yyyy ساعت HH:mm:ss") : "", PublisherName = item.BookGroups.First().PublisherName, Stock = item.BookGroups.First().Stock, Translator = TranslatorName, Category = CategoryName, Language = item.BookGroups.First().LanguageName, }; viewModels.Add(VM); } return(viewModels); }
public ActionResult Index(string search, int?page) { BookIndexViewModel model = new BookIndexViewModel(); return(View(model.CreateModel(search, 20, page))); }