示例#1
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            if (userId != null)
            {
                //an user is logged in

                var userProfile = _userProfileService.GetUserProfileByUserId(new Guid(userId));
                if (userProfile == null)
                {
                    //new user so we create new UserProfile
                    var user           = _userService.GetUserById(userId);
                    var newUserProfile = _userProfileService.CreateNewUserProfile(user);
                    _friendsService.CreateEmptyFriendsEntity(newUserProfile);

                    userProfile = newUserProfile;
                }
                List <HomeIndexPostViewModel> posts = null;
                if (userProfile != null)
                {
                    posts = _postService.GetPosts(userProfile.Id);
                }

                var viewModel = new HomeIndexViewModel
                {
                    Posts     = posts,
                    PostModel = new Post()
                };
                return(View(viewModel));
            }
            else
            {
                // no user is logged in
                ViewBag.userAddress = '0';
                return(View(new HomeIndexViewModel()));
            }
        }