private async Task <UserProfileVM> BuildUserProfile(string email) { var getFromSession = GetUserProfile(); if (!string.IsNullOrEmpty(getFromSession.Name)) { return(getFromSession); } var user = await _userManager.GetUser(email); var userProfile = new UserProfileVM { Name = $"{user.FirstName} {user.Surname}", Email = user.EmailAddress, PhoneNo = user.PhoneNumber, IsApproved = user.IsApproved, AccessArea = user.AllowedAccessAreas, BooksNotReturned = await _booksLibraryManager.BooksOnLoan(email) }; if (userProfile.AccessArea != null && userProfile.AccessArea.Contains(UserLevel.AccessArea.LibraryAdmin)) { userProfile.BookLendingRequests = await _booksLibraryManager.GetNewLendingRequests(); userProfile.RegistrationWaitingToBeApproved = await _userManager.RegistrationWaitingToBeApproved(); } var str = JsonConvert.SerializeObject(userProfile); HttpContext.Session.SetString("userProfile", str); return(userProfile); }
public async Task <IActionResult> LentOutRequest(bool isRequest) { if (string.IsNullOrEmpty(LoggedInName()) || !IsAllowed(UserLevel.AccessArea.LibraryAdmin)) { return(RedirectToAction("Login", "User")); } var model = new List <LendingRequestModel>(); if (GetUserProfile().BookLendingRequests.Any()) { model = GetUserProfile().BookLendingRequests; } else { model = await _booksLibraryManager.GetNewLendingRequests(); } model = isRequest ? model.Where(r => r.LentOn == null).ToList() : model.Where(r => r.LentOn != null).ToList(); ViewBag.isRequest = isRequest; return(View(model)); }