/// <summary> /// The lawyer has chosen to save their changes made on the form presented on GET. Add relationships between /// the lawyer to the chosen libraries via the LawyerLibraryJunction table. /// </summary> /// <returns>RedirectToPageResult for Index on successful creation of relationships between the lawyer and /// all selected libraries. PageResult if ModelState was invalid or if some error occurred with creating / removing /// rows on the LawyerLibraryJunction table to allow the user an opportunity to try again.</returns> public async Task <IActionResult> OnPostAsync() { Lawyer lawyer = await _lawyerService.GetLawyerByPrincipalAsync(User); // Try to merge the state of Lawyer <-> Library relationships if (!ModelState.IsValid || !(await _lawyerService.MergeLibraryListWithLawyerAsync( lawyer.ApplicationUserId, SelectedLibraryIds))) { // Something went wrong; give the user another opportunity to modify their libraries return(Page()); } // Success! Redirect to index return(RedirectToPage("Index")); }