Beispiel #1
0
        public ActionResult Create(BookAuthorViewModel viewModel)
        {
            try
            {
                if (viewModel.AuthorId == -1)
                {
                    ViewBag.Message = "Please select an author from the list ";

                    var model = new BookAuthorViewModel
                    {
                        Authors = FillSelectList()
                    };
                    return(View(model));
                }

                var  author = authorRepository.Find(viewModel.AuthorId);
                Book book   = new Book
                {
                    id          = viewModel.BookId,
                    Title       = viewModel.Title,
                    Description = viewModel.Descrption,
                    Author      = author
                };
                bookRepository.Add(book);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(Author author)
        {
            try
            {
                authorReporsitory.Add(author);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }