/// <summary> /// Returns a FeedsListModel with all the feed of the input userId, if the userId is -1, all feed is returned /// </summary> /// <param name="userID"></param> /// <returns></returns> public FeedsListModel getAllFeedByUserId(int userID) { //first we need the relation type object IRelationType relationTypeToFetch = _relationService.GetRelationTypeByAlias("feedToUser"); IEnumerable<IRelation> listOfRelationFeedToUser; //now we can create a relation list and sort it if (userID >= 0) { listOfRelationFeedToUser = _relationService.GetAllRelationsByRelationType(relationTypeToFetch.Id).Where(x => x.ChildId == userID); } else { listOfRelationFeedToUser = _relationService.GetAllRelationsByRelationType(relationTypeToFetch.Id); } //now let's create FeedListModel to store our feedlist FeedsListModel listOfAllFeeds = new FeedsListModel(); //now let's looop over the relation to extract the information we need foreach (var item in listOfRelationFeedToUser) { FeedViewModel feedViewModelToStore = new FeedViewModel(); //in the relation the child is the member id feedViewModelToStore.author = _memberService.GetById(item.ChildId); //and the parent is the feed //we are going to be using the ipublished version here for the front end var umbHelper = new UmbracoHelper(UmbracoContext.Current); feedViewModelToStore.feed = umbHelper.TypedContent(item.ParentId); //let's make sure neither is null , else we will not add the feedviewmodel to our collection if (feedViewModelToStore.author != null && feedViewModelToStore.feed != null) { listOfAllFeeds.feeds.Add(feedViewModelToStore); } } listOfAllFeeds.feeds = listOfAllFeeds.feeds.OrderByDescending(x => x.feed.CreateDate).ToList(); return listOfAllFeeds; }
public FeedsListModel renderAccptedFeed() { //now we got a list of all accepted friends for the logged in user FriendRequestsViewModel acceptedFriends = acceptedFriendsToViewModel(); //lets create a feeds list model to return FeedsListModel feedsListToReturn = new FeedsListModel(); //now createa a collection of feeds from all the users foreach (var a in acceptedFriends.friendRequests) { var allFeedFromUser = _myHelper.getAllFeedByUserId(a.Id); feedsListToReturn.feeds.AddRange(allFeedFromUser.feeds); } //lets fix the order of things feedsListToReturn.feeds = feedsListToReturn.feeds.OrderByDescending(x => x.feed.CreateDate).ToList(); return feedsListToReturn; }