예제 #1
0
        public ActionResult Create()
        {
            var authorRepo = new AuthorRepository();
            var bookModel = new CreateBookViewModel();

            bookModel.Authors = new SelectList(authorRepo.GetAllAuthors(), "Id", "FirstName", 1);

            return View(bookModel);
        }
예제 #2
0
        public ActionResult Create(string firstName, string lastName)
        {
            if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName))
            {
                throw new ArgumentOutOfRangeException();
            }

            var authorRepo = new AuthorRepository();
            var authorToAdd = new Author();

            authorToAdd.FirstName = firstName;
            authorToAdd.LastName = lastName;

            authorRepo.AddAuthor(authorToAdd);

            return RedirectToAction("Index");
        }
예제 #3
0
        public ActionResult Create(string title, int quantity, int authorId)
        {
            if (title.Length < 1 || quantity < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var authorRepo = new AuthorRepository();
            var bookToAdd = new Book();

            bookToAdd.Title = title;
            bookToAdd.Quantity = quantity;

            var bookRepo = new BookRepository();
            bookRepo.AddBook(bookToAdd);

            authorRepo.AddBookToAuthor(authorId, bookToAdd);

            return RedirectToAction("Create");
        }
예제 #4
0
        public ActionResult Index()
        {
            var authorRepo = new AuthorRepository();

            return View(authorRepo.GetAllAuthors());
        }