Beispiel #1
0
        public ActionResult Create(AddBookFormModel addBookForm)
        {
            try
            {
                var author = new Author()
                {
                    FirstName = addBookForm.AuthorFirstName,
                    LastName  = addBookForm.AuthorLastName
                };

                var book = new Book
                {
                    Title         = addBookForm.Title,
                    AuthorId      = author.Id,
                    YearPublished = addBookForm.YearPublished,
                    Genre         = addBookForm.Genre,
                    //Location = addBookForm.Location
                };

                repository.AddBook(book, author);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #2
0
        // GET: Books/Create
        public ActionResult Create()
        {
            var bookLocations      = new List <Location>();
            AddBookFormModel model = new AddBookFormModel();

            model.Locations = repository.GetLocations();

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Add(AddBookFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await this.userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound());
            }

            await this.books.AddAsync(model.Title, model.Description, user.Id);

            TempData.AddSuccessMessage($"Successfully added book {model.Title} by {user.UserName}");

            return(this.RedirectToActionExtensionMethod(nameof(Index)));
        }