Ejemplo n.º 1
0
        public PartialViewResult UpdatePostWall(string Id)
        {
            List <PostModels>      posts = postRepository.GetAllPostsForUserById(Id);
            PostViewModelsForUsers model = ConvertPostToPostViewModelForUsers(posts, Id);

            return(PartialView("_PostWall", model));
        }
Ejemplo n.º 2
0
        // GET: Profile
        public ActionResult Index()
        {
            object profileId     = Request.RequestContext.RouteData.Values["id"];
            string currentUserId = User.Identity.GetUserId();

            if (string.IsNullOrWhiteSpace((string)profileId))
            {
                profileId = currentUserId;
            }

            // Add user to visitor list for the visited profile, but remove them first if they're already in the 5 latest
            if (!string.Equals(currentUserId, (string)profileId))
            {
                List <VisitorModels> allVisitors = visitorRepository.GetAllVisitorsByUserId((string)profileId);                // Everyone who has looked at this profile
                if (allVisitors.Any((v) => v.VisitFromId.Equals(currentUserId)))                                               // If current user has already visited this profile
                {
                    visitorRepository.Remove(visitorRepository.GetVisitIdByVisitFromUserId((string)profileId, currentUserId)); // Remove the visit by the current user
                }
                VisitorModels visitor = new VisitorModels {
                    VisitDateTime = DateTime.Now,
                    VisitFromId   = currentUserId,
                    VisitToId     = (string)profileId
                };
                visitorRepository.Add(visitor);
                visitorRepository.Save();
            }

            ProfileModels            userProfile              = profileRepository.Get((string)profileId);
            List <PostModels>        posts                    = postRepository.GetAllPostsForUserById((string)profileId);
            List <FriendModels>      friends                  = friendRepository.GetAllFriendsByUserId((string)profileId);
            PostViewModelsForUsers   postViewModelForUsers    = ConvertPostToPostViewModelForUsers(posts, (string)profileId);
            FriendViewModelsForUsers friendViewModelsForUsers = ConvertFriendToFriendViewModelsForUsers(friends, (string)profileId);

            ProfileViewModel userProfileViewModel = new ProfileViewModel {
                Id           = userProfile.Id,
                FirstName    = userProfile.FirstName,
                LastName     = userProfile.LastName,
                Gender       = userProfile.Gender,
                Biography    = userProfile.Biography,
                BirthDate    = userProfile.BirthDate.ToShortDateString(),
                IsActive     = userProfile.IsActive,
                Posts        = postViewModelForUsers,
                Friends      = friendViewModelsForUsers,
                ProfileImage = userProfile.ProfileImage
            };

            ViewBag.ProfileRelation = GetProfileRelation((string)profileId);

            return(View(userProfileViewModel));
        }
Ejemplo n.º 3
0
        public PostViewModelsForUsers ConvertPostToPostViewModelForUsers(List <PostModels> posts, string userId)
        {
            //Creates an object that contains a List<Post> and properties about the relationship between the inlogged user and the userprofile
            IEnumerable <PostViewModels> postsViewModel = posts.Select((p) => new PostViewModels()
            {
                PostId   = p.Id,
                PostFrom = profileRepository.Get(p.PostFromId),
                Text     = p.Text,
                TimeAgo  = p.PostDateTime
            });

            PostViewModelsForUsers model = new PostViewModelsForUsers {
                UserId   = userId,
                PostList = postsViewModel.ToList()
            };

            return(model);
        }