Ejemplo n.º 1
0
        public IActionResult Index(string SearchBook = null, string SearchAuthor = null)
        {
            var model = new BooksIndexViewModel();

            model.Books = bookService.GetBooks(SearchBook, SearchAuthor);
            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Books
        public ActionResult Index(int?pageIndex, string sortBy)
        {
            var books = new BooksIndexViewModel()
            {
                BookList = new List <Book>
                {
                    new Book {
                        ID = 1, Name = "Dances With Wolves"
                    },
                    new Book {
                        ID = 2, Name = "Dune"
                    }
                }
            };

            return(View(books));
        }
Ejemplo n.º 3
0
        // GET: Books
        public async Task <IActionResult> Index(BooksIndexViewModel model)
        {
            model.Pager ??= new PagerViewModel();
            model.Pager.CurrentPage = model.Pager.CurrentPage <= 0 ? 1 : model.Pager.CurrentPage;

            List <BooksViewModel> items = await _context.Books.Skip((model.Pager.CurrentPage - 1) *PageSize).Take(PageSize).Select(b => new Book()
            {
                Id     = b.Id,
                Author = b.Author,
                ISBN   = b.ISBN,
                Pages  = b.Pages,
                Price  = b.Price,
                Title  = b.Title
            }).ToListAsync();

            model.Items            = items;
            model.Pager.PagesCount = (int)Math.Ceiling(await _context.Books.CountAsync() / (double)PageSize);

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Books()
        {
            var viewModel = new BooksIndexViewModel();

            try
            {
                var books   = _repository.GetBooks();
                var authors = _repository.GetAuthors();
                viewModel.PrepareData(books, authors);
            }
            catch (Exception e)
            {
                var errorModel = new ErrorModel
                {
                    Message = "Greška prilikom dohvaćanja knjiga"
                };

                return(View("Error", errorModel));
            }

            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public List <BooksIndexViewModel> GetBooks(string title, string ISBN, string Language, string Publisher, string Author, string Translator, string Category)
        {
            string AuthorName     = "";
            string TranslatorName = "";
            string CategoryName   = "";
            List <BooksIndexViewModel> BooksViewModel = new List <BooksIndexViewModel>();
            //var Books = (from b in _context.Books
            //            join p in _context.Publishers on b.PublisherID equals p.PublisherID
            //            join u in _context.Author_Books on b.BookID equals u.BookID
            //            join a in _context.Authors on u.AuthorID equals a.AuthorID
            //            where b.Delete == false
            //            select new BooksIndexViewModel
            //            {
            //                BookId = b.BookID,
            //                ISBN = b.ISBN,
            //                IsPublish = b.IsPublish,
            //                Price = b.Price,
            //                PublishDate = b.PublishDate,
            //                Stock = b.Stock,
            //                Title = b.Title,
            //                PublisherName=p.PublisherName,
            //                Author= a.FirstName + " " + a.LastName,
            //            }).GroupBy(b=>b.BookId).Select(g=> new { BookID=g.Key, BookGroups=g }).ToList();

            var Books = (from u in _context.Author_Books
                         .Include(a => a.Author)
                         .Include(b => b.Book)
                         .ThenInclude(p => p.publisher)
                         join l in _context.Languages on u.Book.LanguageID equals l.LanguageID
                         join tt in _context.Book_Translators on u.BookID equals tt.BookID into ttc
                         from bttc in ttc.DefaultIfEmpty()
                         join t in _context.Translator on bttc.TranslatorID equals t.TranslatorID into tc
                         from btc in tc.DefaultIfEmpty()
                         join cc in _context.Book_Categories on u.BookID equals cc.BookID into cct
                         from bcct in cct.DefaultIfEmpty()
                         join c in _context.Categories on bcct.CategoryID equals c.CategoryID into ct
                         from bct in ct.DefaultIfEmpty()
                         //.ThenInclude(tt => tt.Book_Translator)
                         //.ThenInclude(t=>t.Translator)
                         where (u.Book.Delete == false &&
                                u.Book.Title.Contains(title.TrimEnd().TrimStart()) &&
                                u.Book.ISBN.Contains(ISBN.TrimEnd().TrimStart()) &&
                                u.Book.publisher.PublisherName.Contains(Publisher.TrimEnd().TrimStart()) &&
                                l.LanguageName.Contains(Language.TrimEnd().TrimStart()) &&
                                EF.Functions.Like(l.LanguageName, "%" + Language + "%")
                                )
                         select new BooksIndexViewModel
            {
                Author = u.Author.FirstName + " " + u.Author.LastName,
                Translator = bttc != null ? btc.Name + " " + btc.Family : "",
                Category = bcct != null ? bct.CategoryName : "",
                BookID = u.Book.BookID,
                ISBN = u.Book.ISBN,
                IsPublish = u.Book.IsPublish,
                Price = u.Book.Price,
                PublishDate = u.Book.PublishDate,
                PublisherName = u.Book.publisher.PublisherName,
                Stock = u.Book.Stock,
                Title = u.Book.Title,
                Language = l.LanguageName,
            }).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 }).ToList();

            foreach (var item in Books)
            {
                AuthorName     = "";
                TranslatorName = "";
                CategoryName   = "";
                foreach (var itemGroup in item.BookGroups.Select(a => a.Author).Distinct())
                {
                    if (AuthorName == "")
                    {
                        AuthorName = itemGroup;
                    }
                    else
                    {
                        AuthorName = AuthorName + " - " + itemGroup;
                    }
                }
                foreach (var itemGroup in item.BookGroups.Select(a => a.Translator).Distinct())
                {
                    if (TranslatorName == "")
                    {
                        TranslatorName = itemGroup;
                    }
                    else
                    {
                        TranslatorName = TranslatorName + " - " + itemGroup;
                    }
                }
                foreach (var itemGroup in item.BookGroups.Select(a => a.Category).Distinct())
                {
                    if (CategoryName == "")
                    {
                        CategoryName = itemGroup;
                    }
                    else
                    {
                        CategoryName = CategoryName + " - " + itemGroup;
                    }
                }

                BooksIndexViewModel vm = new BooksIndexViewModel()
                {
                    Author        = AuthorName,
                    Translator    = TranslatorName,
                    Category      = CategoryName,
                    BookID        = item.BookID,
                    ISBN          = item.BookGroups.First().ISBN,
                    IsPublish     = item.BookGroups.First().IsPublish,
                    Price         = item.BookGroups.First().Price,
                    PublishDate   = item.BookGroups.First().PublishDate,
                    PublisherName = item.BookGroups.First().PublisherName,
                    Stock         = item.BookGroups.First().Stock,
                    Title         = item.BookGroups.First().Title,
                    Language      = item.BookGroups.First().Language,
                };
                BooksViewModel.Add(vm);
            }
            return(BooksViewModel);
        }
Ejemplo n.º 6
0
        public List <BooksIndexViewModel> GetAllBooks(string title, string ISBN, string Language, string Publisher, string Author, string Translator, string Category)
        {
            string autherNames     = "";
            string trnaslatorsName = "";
            string categoriesName  = "";
            List <BooksIndexViewModel> viewModel = new List <BooksIndexViewModel>();
            List <int> rows = new List <int> {
                5, 10, 15, 20, 50, 100
            };

            //var books = context.Author_Books.Include(b => b.Book).ThenInclude(p => p.Publisher).Include(a => a.Author)
            //    .Include(l => l.Book.Language)
            //    .Where(c => c.Book.IsDeleted == false && c.Book.Title.Contains(title.Trim()) && c.Book.ISBN.Contains(ISBN.Trim())
            //    && c.Book.Language.LanguageName.Contains(Language.Trim()) && c.Book.Publisher.PublisherName.Contains(Publisher.Trim())).Select(c => new
            //{
            //    Author = c.Author.FirstName + " " + c.Author.LastName,
            //    c.BookID,
            //    c.Book.ISBN,
            //    c.Book.IsPublished,
            //    c.Book.Price,
            //    c.Book.PublishDate,
            //    c.Book.Publisher.PublisherName,
            //    c.Book.Stock,
            //    c.Book.Title

            //}).Where(a => a.Author.Contains(Author)).GroupBy(b => b.BookID).Select(g => new { BookID = g.Key, BookGroups = g }).ToList();

            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.Translators 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.IsDeleted == 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()))
                         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.IsPublished,
                u.Book.Price,
                u.Book.PublishDate,
                u.Book.Publisher.PublisherName,
                u.Book.Stock,
                u.Book.Title,
            }).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 }).ToList();;



            foreach (var item in books)
            {
                autherNames     = "";
                trnaslatorsName = "";
                categoriesName  = "";
                foreach (var group in item.BookGroups.Select(a => a.Author).Distinct())
                {
                    if (autherNames == "")
                    {
                        autherNames = group;
                    }
                    else
                    {
                        autherNames = autherNames + " - " + group;
                    }
                }
                foreach (var group in item.BookGroups.Select(a => a.Translator).Distinct())
                {
                    if (trnaslatorsName == "")
                    {
                        trnaslatorsName = group;
                    }
                    else
                    {
                        trnaslatorsName = trnaslatorsName + " - " + group;
                    }
                }
                foreach (var group in item.BookGroups.Select(a => a.Category).Distinct())
                {
                    if (categoriesName == "")
                    {
                        categoriesName = group;
                    }
                    else
                    {
                        categoriesName = categoriesName + " - " + group;
                    }
                }
                BooksIndexViewModel vm = new BooksIndexViewModel()
                {
                    Author        = autherNames,
                    BookID        = item.BookID,
                    ISBN          = item.BookGroups.First().ISBN,
                    Title         = item.BookGroups.First().Title,
                    Price         = item.BookGroups.First().Price,
                    IsPublish     = item.BookGroups.First().IsPublished,
                    PublishDate   = item.BookGroups.First().PublishDate,
                    PublisherName = item.BookGroups.First().PublisherName,
                    Stock         = item.BookGroups.First().Stock,
                    Translator    = trnaslatorsName,
                    Category      = categoriesName,
                    Language      = item.BookGroups.First().LanguageName,
                };
                viewModel.Add(vm);
            }
            return(viewModel);
        }
Ejemplo n.º 7
0
        public List <BooksIndexViewModel> GetAllBooks(string title, string ISBN, string Language, string Publisher, string Author, string Translator, string Category)
        {
            string AuthersName    = "";
            string TranslatorName = "";
            string CategotyName   = "";
            List <BooksIndexViewModel> ViewModel = new List <BooksIndexViewModel>();
            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 = trl != null?trl.Name + " " + trl.Family :"",
                Category = cog != null ? cog.CategoryName : "",
                u.Book.BookID,
                u.Book.ISBN,
                u.Book.IsPublish,
                u.Book.Price,
                u.Book.PublishDate,
                u.Book.Publisher.PublisherName,
                u.Book.Stock,
                u.Book.Title,
                l.LanguageName,
            }).Where(a => a.Author.Contains(Author.TrimStart().TrimEnd()) && a.Translator.Contains(Translator.TrimStart().TrimEnd()) && a.Category.Contains(Category.TrimStart().TrimEnd()))
                        .GroupBy(b => b.BookID).Select(g => new { BookID = g.Key, BookGroups = g }).ToList();

            foreach (var item in Books)
            {
                AuthersName    = "";
                TranslatorName = "";
                CategotyName   = "";
                foreach (var a in item.BookGroups.Select(a => a.Author).Distinct())
                {
                    if (AuthersName == "")
                    {
                        AuthersName = a;
                    }
                    else
                    {
                        AuthersName = AuthersName + " - " + a;
                    }
                }

                foreach (var a in item.BookGroups.Select(a => a.Translator).Distinct())
                {
                    if (TranslatorName == "")
                    {
                        TranslatorName = a;
                    }
                    else
                    {
                        TranslatorName = TranslatorName + " - " + a;
                    }
                }

                foreach (var a in item.BookGroups.Select(a => a.Category).Distinct())
                {
                    if (CategotyName == "")
                    {
                        CategotyName = a;
                    }
                    else
                    {
                        CategotyName = CategotyName + " - " + a;
                    }
                }

                BooksIndexViewModel VM = new BooksIndexViewModel()
                {
                    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,
                                      Language      = item.BookGroups.First().LanguageName,
                                      Category      = CategotyName,
                                      Translator    = TranslatorName,
                };

                ViewModel.Add(VM);
            }

            return(ViewModel);
        }