Exemple #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);
        }
        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");
        }
Exemple #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");
        }
        public ActionResult Index()
        {
            var authorRepo = new AuthorRepository();

            return View(authorRepo.GetAllAuthors());
        }