public AuthorWithBooksViewModel GetAuthorDetails(int?id)
        {
            Author author = this.Context.Authors.Find(id);

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

            AuthorWithBooksViewModel viewModel = Mapper.Map <Author, AuthorWithBooksViewModel>(author);

            return(viewModel);
        }
        // GET: Admin/Authors/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AuthorWithBooksViewModel viewModel = this.authorService.GetAuthorDetails(id);

            if (viewModel == null)
            {
                throw new Exception($"Invalid URL - there is no author with id {id}");
            }

            return(View(viewModel));
        }
        public ActionResult BooksByAuthorFullName(string authorName)
        {
            if (string.IsNullOrEmpty(authorName))
            {
                this.TempData["Error"] = "Enter author's name to find books.";
                return(View());
            }

            AuthorWithBooksViewModel viewModel = this.authorService.GetAuthorWithBooks(authorName);

            if (viewModel == null)
            {
                throw new Exception($"Invalid URL - there is no author with name {authorName}");
            }

            return(View(viewModel));
        }
        public AuthorWithBooksViewModel GetAuthorWithBooks(string authorName)
        {
            authorName = HttpUtility.HtmlDecode(authorName.Trim());

            Author author = this.Context.Authors
                            .Include("Books")
                            .FirstOrDefault(a => a.FullName.Contains(authorName));

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

            AuthorWithBooksViewModel viewModel = Mapper.Map <Author, AuthorWithBooksViewModel>(author);
            var authorBooks = author.Books.OrderByDescending(b => b.IssueDate).ToList();

            viewModel.Books = Mapper.Map <ICollection <Book>, ICollection <BooksViewModel> >(authorBooks);
            return(viewModel);
        }