Example #1
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = UploadsFile(model.Img) ?? string.Empty;

                    if (model.AuthorId == -1)
                    {
                        ViewBag.message = "Please select an author";
                        return(View(getAllAuthors()));
                    }

                    var  author = authorRepository.Find(model.AuthorId);
                    Book book   = new Book
                    {
                        Id          = model.Id,
                        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()));
        }
Example #2
0
        // GET: Author/Details/5
        public ActionResult Details(int id)
        {
            var author = authorRepository.Find(id);

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

            return(View(book));
        }