Example #1
0
        public IEnumerable<PostDetails> execute(GetPostsRequest the_request)
        {
            set_request(the_request)
                .get_connection();

            if (request.first_load)
            {
                var latest_post = post_repository.Entities.AsEnumerable().LastOrDefault();
                if (latest_post != null)
                {
                    request.start_index = latest_post.ID;
                    request.collection_traversal = CollectionTraversal.Older;
                }
            }

            var query_repository = post_repository.Entities;

            if (request.category == GetPostsQueryCategory.ByRadius)
            {
                query_repository = get_posts_by_radius.execute(new GetPostsByRadiusRequest() { geo_location = connection.GeoLocation });
            }
            else if (request.category == GetPostsQueryCategory.ByHashTag)
            {
                var hash_tag = get_hash_tag_by_name.execute(new GetHashTagByNameRequest() { hash_tag_name = request.hash_tag_name });
                query_repository = get_posts_by_hash_tag.execute(new GetPostsByHashTagRequest() { hash_tag_id = hash_tag.ID });
            }

            return
               query_repository
                        .AsEnumerable()
                        .Where(p => (request.collection_traversal == CollectionTraversal.Older ? p.ID <= request.start_index : p.ID >= request.start_index))
                        .Order(p => request.category == GetPostsQueryCategory.ByRadius
                                                        ? p.ID
                                                        : p.GeoLocation.Geoposition.Distance(connection.GeoLocation.Geoposition)
                                    , request.category == GetPostsQueryCategory.ByRadius
                                                        ? request.collection_traversal != CollectionTraversal.Older
                                                        :true)
                        .Take(request.max_results > 0 ? request.max_results : 10)
                //.AsEnumerable()
                        .Select(p => new PostDetails
                        {
                            image_id = p.image_id,
                            text = p.Text,
                            date = p.DateTime,
                            post_id = p.ID,
                            user_id = p.User.ID,
                            user_display_name = p.User.DisplayName,
                            long_lat_acc_geo_string = string.Format("{0},{1},{2}", p.GeoLocation.Geoposition.Longitude, p.GeoLocation.Geoposition.Latitude, p.GeoLocation.AccuracyInMetres)
                        });
        }
Example #2
0
        private GetPosts set_request(GetPostsRequest the_request)
        {
            request = Guard.IsNotNull(the_request, "the_request");

            return this;
        }