Ejemplo n.º 1
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = string.Empty;



                    if (model.AuthorId == -1)
                    {
                        ViewBag.Message = "Please Select an Author from the List";

                        return(View(GetAllAuthor()));
                    }
                    var  author = authorRepository.Find(model.AuthorId);
                    Book book   = new Book
                    {
                        Id          = model.BookId,
                        Title       = model.Title,
                        Description = model.Description,
                        Author      = author,
                        ImageUrl    = fileName
                    };
                    bookStoreRepoitory.Add(book);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }

            ModelState.AddModelError("", "You have to fill all the required fields");
            return(View(GetAllAuthor()));
        }
Ejemplo n.º 2
0
        // GET: BookController/Details/5
        public ActionResult Details(int id)
        {
            var book = bookStoreRepoitory.Find(id);

            return(View(book));
        }
Ejemplo n.º 3
0
        // GET: Author/Details/5
        public ActionResult Details(int id)
        {
            var author = authorRepository.Find(id);

            return(View(author));
        }