public IHttpActionResult Get([FromUri] TimelinePostsRequestModel model) { var customerId = model.CustomerId; var page = model.Page; //we need to get posts from followers, friends, self, and anything else that supports posting to timeline //but we need to know if the current customer is a registered user or a guest var isRegistered = ApplicationContext.Current.CurrentUser.IsRegistered(); //the posts that'll be returned List <TimelinePost> timelinePosts = null; //the number of posts var count = model.Count; //if the user is registered, then depending on value of customerId, we fetch posts. //{if the customer id matches the logged in user id, he is seeing his own profile, so we show the posts by her only //{if the customer id is zero, then we show posts by her + posts by her friends + posts by people she is following etc. //{if the customer id is non-zero, then we show posts by the customer of customerId if (isRegistered) { if (customerId != 0) { //we need to get posts by this customer timelinePosts = _timelineService.GetByEntityIds("customer", new[] { customerId }, true, count, page).ToList(); } else { customerId = ApplicationContext.Current.CurrentUser.Id; //we need to find he person she is following. var allFollows = _customerFollowService.GetCustomerFollows <User>(customerId); //get all the customer's ids which she is following var customerIds = allFollows.Where(x => x.FollowingEntityName == typeof(User).Name) .Select(x => x.FollowingEntityId).ToList(); //and add current customer has well to cover her own posts customerIds.Add(ApplicationContext.Current.CurrentUser.Id); //get timeline posts timelinePosts = _timelineService.GetByEntityIds("customer", customerIds.ToArray(), true, count, page).ToList(); } } else { //should we show the data to non logged in user? //return null; timelinePosts = _timelineService.GetByEntityIds("customer", new[] { customerId }, true, count, page).ToList(); } var responseModel = new List <TimelinePostDisplayModel>(); foreach (var post in timelinePosts) { var postModel = PrepareTimelinePostDisplayModel(post); responseModel.Add(postModel); } return(Response(responseModel)); }