Пример #1
0
        //[HttpPost]
        //public string Index(string searchString, bool notused)
        //{
        //    return "From [HttpPost]Index: filter on " + searchString;
        //}

        // GET: Books/Details/5
        public async Task <IActionResult> Details(int?id, string returnURL)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var author = await authorsService.GetAuthor(id);

            if (author == null)
            {
                return(NotFound());
            }

            author.ReturnUrl = returnURL;

            var books = await booksService.GetAll();

            books = books.Where(s => s.Autor.Id == author.Id).ToList();

            author.BooksforAuthor = books.ToList();
            return(View(author));
        }
Пример #2
0
        // GET: Books
        public async Task <IActionResult> Index(int?bookAutor, string searchString, int?bookDateTimeto, int?bookDateTimefrom)
        {
            var autorQuery = await authorsService.GetAll();

            var books = await booksService.GetAll();

            var dates = books
                        .OrderBy(x => x.ReleaseDate)
                        .Select(x => x.ReleaseDate.ToString("d"));

            if (!String.IsNullOrEmpty(searchString))
            {
                books = books.Where(s => s.Title.Contains(searchString)).ToList();
            }


            if (bookDateTimeto.HasValue && bookDateTimefrom.HasValue)
            {
                books = books.Where(x => x.ReleaseDate.Year >= bookDateTimeto && x.ReleaseDate.Year <= bookDateTimefrom).ToList();
            }



            if (bookAutor.HasValue)
            {
                books = books.Where(x => x.Autor.Id == bookAutor).ToList();
            }

            var bookAutorVM = new BookAutorViewModel
            {
                Autors = new SelectList(autorQuery, nameof(Autor.Id), nameof(Autor.Name)),
                Dates  = new SelectList(dates.Distinct()),
                Books  = books
            };

            return(View(bookAutorVM));
        }