public async Task <IActionResult> Create( [Bind("Title, Authors, PagesNumber, Publisher, ReleaseYear")] BookViewModel bookViewModel, [FromForm(Name = "uploadImage")] IFormFile uploadImage) { //int authorId; //bool IsAuthorExists; try { if (ModelState.IsValid) { if (uploadImage != null) { bookViewModel.Image = UploadImage(uploadImage); } var book = new Book() { Title = bookViewModel.Title, PagesNumber = bookViewModel.PagesNumber, Publisher = bookViewModel.Publisher, ReleaseYear = bookViewModel.ReleaseYear, Image = bookViewModel.Image }; await _booksRepository.AddBookData(book); foreach (var author in bookViewModel.Authors) { await AddAuthorForBookToRelationsDatabase(book.Id, author); } return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /*ex*/) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(bookViewModel)); }