예제 #1
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = Uploadfile(model.File) ?? string.Empty;
                    if (model.Author == -1)
                    {
                        ViewBag.Message = "Please select an author from the list!";
                        var ViewModel = getAllAuthors();
                        return(View(ViewModel));
                    }
                    var author = authorRepository.find(model.Author);
                    var book   = new Book
                    {
                        Id          = model.BookId,
                        Title       = model.Title,
                        Description = model.Description,
                        Author      = author,
                        ImageUrl    = fileName
                    };

                    bookRepository.Add(book);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }
            ModelState.AddModelError("", "You have to fill all the required fields!");

            return(View(getAllAuthors()));
        }
예제 #2
0
        // GET: Author/Details/5
        public ActionResult Details(int id)
        {
            var author = authorRepository.find(id);

            return(View(author));
        }
예제 #3
0
        // GET: Book/Details/5
        public ActionResult Details(int id)
        {
            var book = bookRepository.find(id);

            return(View(book));
        }