private async Task<MyAccountViewModel> GetMyAccountVm(MyAccountRequest request, IMyMentorRepository repository) { var model = new MyAccountViewModel {MyAccountRequest = request}; var isAdmin = Session.GetLoggedInUserRoleName() == RoleNames.ADMINISTRATORS || !string.IsNullOrEmpty(Session.GetImpersonatingUserName()); var currentUser = Session.GetLoggedInUser(); var isFirstTimeInPage = Request.QueryString.AllKeys.All(x => x.ToLower() != "uid" && x.ToLower() != "pn"); var userManager = new MyMentorUserManager(repository, Session, HttpContext); if (isAdmin && currentUser.Username != request.Uid && !isFirstTimeInPage) { if (!string.IsNullOrEmpty(request.Uid)) { var user = await repository.FindUserByUserName(request.Uid); if (user != null) { model.ErrorMessage = string.Empty; model.UserName = user.UserName; model.UserDispalyName =string.Concat(user.GetLocalizedField("FirstName") ," ", user.GetLocalizedField("LastName")); model.MyAccountRequest.Uid = user.ObjectId; if (Session.GetImpersonatingUserName() != model.UserName) await userManager.ImpersonateUser(user.UserName); else userManager.StopImpersonation(); } else { model.ErrorMessage = MyMentorResources.userNameDoesNotExist; } } else { userManager.StopImpersonation(); } } else { model.UserName = currentUser.Username; model.UserDispalyName = currentUser.GetFullName(Language.CurrentLanguageCode); model.MyAccountRequest.Uid = currentUser.ObjectId; } return model; }