示例#1
0
        public async Task <JsonNetResult> Current()
        {
            var currentAccount = new CurrentAccountViewModel {
                IsLoggedIn = false
            };

            Guid?userId = User.GetCurrentUserId();

            if (userId.HasValue == false)
            {
                return(JsonSuccess(currentAccount));
            }

            UserProfile user = await _userManagement.GetUserProfile(userId.Value);

            if (user == null)
            {
                return(JsonSuccess(currentAccount));
            }

            // We have a logged in user
            currentAccount.IsLoggedIn = true;
            currentAccount.Profile    = UserProfileViewModel.FromDataModel(user);
            return(JsonSuccess(currentAccount));
        }
示例#2
0
        public ActionResult Header()
        {
            var model = new ViewNavbarViewModel();

            // If there is a user logged in, lookup their profile
            Guid?userId = User.GetCurrentUserId();

            if (userId != null)
            {
                // Since MVC currently doesn't support async child actions (until ASP.NET vNext), we've got to invoke the async
                // method synchronously (luckily, we won't deadlock here because our async method is using ConfigureAwait(false)
                // under the covers).  See http://aspnetwebstack.codeplex.com/workitem/601 for details.
                UserProfile profile = _userManagement.GetUserProfile(userId.Value).Result;

                model.LoggedInUser = UserProfileViewModel.FromDataModel(profile);
            }

            return(View(model));
        }
示例#3
0
        public async Task <ActionResult> Info(GetAccountInfoViewModel model)
        {
            // Whether we're using the currently logged in user
            bool isCurrentlyLoggedInUser = model.UserId.HasValue == false;

            // Use the user id specified, otherwise default to the currently logged in user
            Guid?userId = model.UserId ?? User.GetCurrentUserId();

            if (userId.HasValue == false)
            {
                throw new InvalidOperationException("No user logged in and no user was specified.");
            }

            UserProfile profile = await _userManagement.GetUserProfile(userId.Value);

            return(View(new AccountInfoViewModel
            {
                UserProfile = UserProfileViewModel.FromDataModel(profile),
                IsCurrentlyLoggedInUser = isCurrentlyLoggedInUser
            }));
        }
示例#4
0
        private async Task <UserProfileViewModel> GetUserProfile(Guid userId)
        {
            UserProfile profile = await _userManagement.GetUserProfile(userId);

            return(UserProfileViewModel.FromDataModel(profile));
        }