Esempio n. 1
0
        // GET: BookController/Edit/5
        public ActionResult Edit(int id)
        {
            try
            {
                var spec = new BooksWithAuthorsSpecification(id);

                var book = bookRepository.GetEntityWithSpec(spec);

                var authorId = book.Author == null ? book.Author.Id = 0 : book.Author.Id;

                var model = new BookAuthorViewModel
                {
                    BookId      = book.Id,
                    Title       = book.Title,
                    Description = book.Description,
                    AuthorId    = authorId,
                    Authors     = authorRepository.List().ToList(),
                    ImageUrl    = book.ImageUrl
                };

                return(View(model));
            }
            catch (Exception)
            {
                return(View());
            }
        }
Esempio n. 2
0
        // GET: BookController
        public ActionResult Index()
        {
            var spec = new BooksWithAuthorsSpecification();

            var books = bookRepository.List(spec);

            return(View(books));
        }
Esempio n. 3
0
        // GET: BookController/Details/5
        public ActionResult Details(int id)
        {
            var spec = new BooksWithAuthorsSpecification(id);

            var book = bookRepository.GetEntityWithSpec(spec);

            return(View(book));
        }
Esempio n. 4
0
        // GET: BookController/Search
        public ActionResult Search(string term)
        {
            try
            {
                var spec = new BooksWithAuthorsSpecification(term);

                var books = bookRepository.List(spec);

                return(View("Index", books));
            }
            catch
            {
                return(View());
            }
        }