예제 #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
        // GET: Book/Details/5
        public ActionResult Details(int id)
        {
            var book = bookstore.Find(id);

            return(View(book));
        }