public IActionResult AddToLibrary(int bookid) { if (User.Identity.IsAuthenticated && accountRepository.Accounts.Any(u => u.Username == User.Identity.Name)) { Accounts authenticatedAccount = accountRepository.Accounts.First(u => u.Username == User.Identity.Name); if (libraryRepository.BookLibraryExists(bookid, authenticatedAccount.AccountId)) { TempData["ValidationState"] = "Book Exists in Library"; return(RedirectToAction(TempData["ViewState"].ToString(), TempData["ControllerState"].ToString())); } else { TempData["ValidationState"] = null; } int libraryid = libraryRepository.GetID() + 1; if (libraryRepository.Library.Any(l => l.LibraryId == libraryid)) { libraryid += 1; } libraryRepository.AddLibrary(new Library { /*LibraryId = libraryid,*/ AccountId = authenticatedAccount.AccountId, BookId = bookid, Datecreated = DateTime.Now }); return(RedirectToAction("Index", "Library")); } return(RedirectToAction("Index", "Home")); }