Example #1
0
        public IQueryable <PostDetailModel> GetByTags(string tags, string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                () =>
            {
                VerifySessionKey(sessionKey);

                if (tags == null)
                {
                    throw new InvalidOperationException("Incorrect tags data");
                }

                string[] tagsConstraintSplit = tags.ToLower().Split(new string[] { "," }, StringSplitOptions.None);

                if (tagsConstraintSplit.Length == 0)
                {
                    throw new InvalidOperationException("Incorrect tags data");
                }

                HashSet <string> tagsConstraint = new HashSet <string>();
                tagsConstraint.UnionWith(tagsConstraintSplit);

                IRepository <Post> postRepository = this.data.GetPostsRepository();

                IQueryable <Post> posts = postRepository.GetConstraint(p => p.Tags.Select(t => t.Name).Intersect(tagsConstraint).Count() == tagsConstraint.Count());

                IQueryable <PostDetailModel> postsModels = ModelFunctions.GetPostsDetails(posts);

                return(postsModels.OrderByDescending(p => p.PostDate));
            });

            return(responseMsg);
        }
Example #2
0
        public IQueryable <PostDetailModel> GetPosts(string sessionKey, int id)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                () =>
            {
                VerifySessionKey(sessionKey);

                IRepository <Tag> tagRepository = this.data.GetTagsRepository();

                Tag tag = tagRepository.Get(id);

                if (tag == null)
                {
                    throw new InvalidOperationException("No such tag");
                }

                IRepository <Post> postRepository = this.data.GetPostsRepository();

                IQueryable <Post> posts = postRepository.GetConstraint(p => p.Tags.Any(t => t.TagId == id));

                IQueryable <PostDetailModel> postsModels = ModelFunctions.GetPostsDetails(posts);

                return(postsModels.OrderByDescending(p => p.PostDate));
            });

            return(responseMsg);
        }
Example #3
0
        public IQueryable <PostDetailModel> Get(string keyword, string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                () =>
            {
                VerifySessionKey(sessionKey);

                IRepository <Post> postRepository = this.data.GetPostsRepository();

                IQueryable <Post> posts = postRepository.GetConstraint(p => p.Title.ToLower().IndexOf(keyword.ToLower()) != -1);

                IQueryable <PostDetailModel> postsModels = ModelFunctions.GetPostsDetails(posts);

                return(postsModels.OrderByDescending(p => p.PostDate));
            });

            return(responseMsg);
        }
Example #4
0
        public IQueryable <PostDetailModel> Get(string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                () =>
            {
                VerifySessionKey(sessionKey);

                IRepository <Post> postRepository = this.data.GetPostsRepository();

                IQueryable <Post> posts = postRepository.All();

                IQueryable <PostDetailModel> postsModels = ModelFunctions.GetPostsDetails(posts);

                return(postsModels.OrderByDescending(p => p.PostDate));
            });

            return(responseMsg);
        }