コード例 #1
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = UploadFile(model.File) ?? string.Empty;
                    if (model.AuthorId == -1)
                    {
                        ViewBag.Message = "Please select an author from the list !!";
                        return(View(GetAllAuthors()));
                    }
                    Book book = new Book
                    {
                        Id          = model.BookId,
                        Author      = authorRepository.Find(model.AuthorId),
                        Description = model.Description,
                        Title       = model.Title,
                        ImageUrl    = fileName
                    };
                    // TODO: Add insert logic here
                    bookRepository.Add(book);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }

            ModelState.AddModelError("", "You have to fill the required fields!!");
            return(View(GetAllAuthors()));
        }
コード例 #2
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.AuthorId == -1)
                    {
                        ViewBag.Message = "Please select an author from the list";

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

                catch
                {
                    return(View());
                }
            }

            ModelState.AddModelError("", "You have to fill all the required fields");
            return(View(GetAllAuthors()));
        }
コード例 #3
0
        public ActionResult Create(BookAuthorViewModel bookModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = UploadFile(bookModel.File) ?? string.Empty;


                    if (bookModel.AuthorId == -1)
                    {
                        ViewBag.Message = "Please select an author from the list!";

                        return(View(LoadAuthorsListModel()));
                    }
                    var  author = authorRepo.Find(bookModel.AuthorId);
                    Book book   = new Book
                    {
                        Id          = bookModel.BookId,
                        Title       = bookModel.Title,
                        Description = bookModel.Description,
                        Author      = author,
                        ImageUrl    = fileName
                    };
                    bookRepo.Add(book);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }
            ModelState.AddModelError("", "Please fill all required fields");
            return(View(LoadAuthorsListModel()));
        }
コード例 #4
0
        public ActionResult Create(BookAuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = UploadFile(model.File) ?? string.Empty;

                    if (model.AuthorId == -1)
                    {
                        ViewBag.Message = "Please select an author";

                        return(View(GetAllAuthors()));
                    }

                    var author = authorRepository.Find(model.AuthorId);

                    // TODO: Add insert logic here
                    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());
                }
            }
            else
            {
                ModelState.AddModelError("", "You have to fill all required fields");
            }
            return(View(GetAllAuthors()));;
        }
コード例 #5
0
        public ActionResult Create(BookAuthorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = UploadFile(viewModel.File) ?? string.Empty;

                    if (viewModel.AuthorId == -1)
                    {
                        ViewBag.Message = "PLease Select an author from the List ";

                        return(View(GetAllAuthors()));
                    }

                    var  author = authorRepository.Find(viewModel.AuthorId);
                    Book Book   = new Book
                    {
                        Id          = viewModel.bookId,
                        Title       = viewModel.Title,
                        Description = viewModel.Description,
                        Author      = author,
                        ImageUrl    = fileName
                    };
                    // TODO: Add insert logic here
                    bookRepository.Add(Book);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }

            ModelState.AddModelError("", "You have to Fill all the required fields");
            return(View(GetAllAuthors()));
        }
コード例 #6
0
        // GET: Author/Details/5
        public ActionResult Details(int id)
        {
            var authorId = authorRepositry.Find(id);

            return(View(authorId));
        }
コード例 #7
0
        // GET: BookController/Details/5
        public ActionResult Details(int id)
        {
            var book = bookRepository.Find(id);

            return(View(book));
        }
コード例 #8
0
        // GET: AutherController/Details/5
        public ActionResult Details(int id)
        {
            var Auther = autherRepository.Find(id);

            return(View(Auther));
        }
コード例 #9
0
        // GET: AuthorController/Details/5
        public ActionResult Details(int id)
        {
            var author = authorRepo.Find(id);

            return(View(author));
        }
コード例 #10
0
ファイル: BookController.cs プロジェクト: abdoa123/BookStore
        // GET: Book/Details/5
        public ActionResult Details(int id)
        {
            var book = bookstore.Find(id);

            return(View(book));
        }