Example #1
0
        public static List <PostCount> GetPostCounts(int catID, string user)
        {
            List <PostCount> postCounts = new List <PostCount>();
            List <PostCount> final      = new List <PostCount>();

            List <Parameter> parameters = Post.GenerateParameters();
            QueryCommand     cmd        = new QueryCommand("Select Status, CategoryId, " + DataService.Provider.SqlCountFunction("Id") + " as StatusCount FROM graffiti_Posts Where IsDeleted = 0");

            if (catID > 0)
            {
                cmd.Sql += " and CategoryId = " + DataService.Provider.SqlVariable("CategoryId");
                cmd.Parameters.Add(Post.FindParameter(parameters, "CategoryId")).Value = catID;
            }

            if (!String.IsNullOrEmpty(user))
            {
                cmd.Sql += " and CreatedBy = " + DataService.Provider.SqlVariable("CreatedBy");
                cmd.Parameters.Add(Post.FindParameter(parameters, "CreatedBy")).Value = user;
            }

            cmd.Sql += " group by Status, CategoryId";

            using (IDataReader reader = DataService.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PostCount postCount = new PostCount();
                    postCount.PostStatus = (PostStatus)Int32.Parse(reader["Status"].ToString());
                    postCount.Count      = Int32.Parse(reader["StatusCount"].ToString());
                    postCount.CategoryId = Int32.Parse(reader["CategoryId"].ToString());

                    postCounts.Add(postCount);
                }

                reader.Close();
            }

            List <PostCount> filteredPermissions = new List <PostCount>();

            filteredPermissions.AddRange(postCounts);

            foreach (PostCount ac in postCounts)
            {
                if (!RolePermissionManager.GetPermissions(ac.CategoryId, GraffitiUsers.Current).Read)
                {
                    filteredPermissions.Remove(ac);
                }
            }

            foreach (PostCount ac in filteredPermissions)
            {
                PostCount existing = final.Find(
                    delegate(PostCount postcount)
                {
                    return(postcount.PostStatus == ac.PostStatus);
                });

                if (existing == null)
                {
                    final.Add(ac);
                }
                else
                {
                    existing.Count += ac.Count;
                }
            }

            return(final);
        }
Example #2
0
        public static List<PostCount> GetPostCounts(int catID, string user)
        {
            List<PostCount> postCounts = new List<PostCount>();
            List<PostCount> final = new List<PostCount>();

            List<Parameter> parameters = Post.GenerateParameters();
            QueryCommand cmd = new QueryCommand("Select Status, CategoryId, " + DataService.Provider.SqlCountFunction("Id") + " as StatusCount FROM graffiti_Posts Where IsDeleted = 0");

            if(catID > 0)
            {
                cmd.Sql += " and CategoryId = " + DataService.Provider.SqlVariable("CategoryId");
                cmd.Parameters.Add(Post.FindParameter(parameters, "CategoryId")).Value = catID;
            }

            if(!String.IsNullOrEmpty(user))
            {
                cmd.Sql += " and CreatedBy = " + DataService.Provider.SqlVariable("CreatedBy");
                cmd.Parameters.Add(Post.FindParameter(parameters, "CreatedBy")).Value = user;
            }

            cmd.Sql += " group by Status, CategoryId";

            using (IDataReader reader = DataService.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PostCount postCount = new PostCount();
                    postCount.PostStatus = (PostStatus)Int32.Parse(reader["Status"].ToString());
                    postCount.Count = Int32.Parse(reader["StatusCount"].ToString());
                    postCount.CategoryId = Int32.Parse(reader["CategoryId"].ToString());

                    postCounts.Add(postCount);
                }

                reader.Close();
            }

            List<PostCount> filteredPermissions = new List<PostCount>();
            filteredPermissions.AddRange(postCounts);

            foreach (PostCount ac in postCounts)
            {
                if (!RolePermissionManager.GetPermissions(ac.CategoryId, GraffitiUsers.Current).Read)
                    filteredPermissions.Remove(ac);
            }

            foreach (PostCount ac in filteredPermissions)
            {
                PostCount existing = final.Find(
                                                delegate(PostCount postcount)
                                                {
                                                    return postcount.PostStatus == ac.PostStatus;
                                                });

                if (existing == null)
                {
                    final.Add(ac);
                }
                else
                {
                    existing.Count += ac.Count;
                }
            }

            return final;
        }