public static List <AuthorCount> GetAuthorCountForStatus(PostStatus status, string categoryID) { List <AuthorCount> autCounts = new List <AuthorCount>(); List <AuthorCount> final = new List <AuthorCount>(); QueryCommand cmd = new QueryCommand( @"select u.Id, " + DataService.Provider.SqlCountFunction("u.Id") + @" as IdCount, u.ProperName, p.CategoryId from graffiti_Posts AS p inner join graffiti_Users as u on p.CreatedBy = u.Name where p.Status = " + DataService.Provider.SqlVariable("Status") + @" and p.IsDeleted = 0"); if (!String.IsNullOrEmpty(categoryID)) { cmd.Sql += " and p.CategoryId = " + DataService.Provider.SqlVariable("CategoryId"); } cmd.Sql += " group by u.Id, u.ProperName, p.CategoryId"; List <Parameter> parameters = Post.GenerateParameters(); cmd.Parameters.Add(Post.FindParameter(parameters, "Status")).Value = (int)status; if (!String.IsNullOrEmpty(categoryID)) { cmd.Parameters.Add(Post.FindParameter(parameters, "CategoryId")).Value = Convert.ToInt32(categoryID); } using (IDataReader reader = DataService.ExecuteReader(cmd)) { while (reader.Read()) { AuthorCount autCount = new AuthorCount(); autCount.ID = Int32.Parse(reader["Id"].ToString()); autCount.Count = Int32.Parse(reader["IdCount"].ToString()); autCount.Name = reader["ProperName"].ToString(); autCount.CategoryId = Int32.Parse(reader["CategoryId"].ToString()); autCounts.Add(autCount); } List <AuthorCount> filteredPermissions = new List <AuthorCount>(); filteredPermissions.AddRange(autCounts); foreach (AuthorCount ac in autCounts) { if (!RolePermissionManager.GetPermissions(ac.CategoryId, GraffitiUsers.Current).Read) { filteredPermissions.Remove(ac); } } foreach (AuthorCount ac in filteredPermissions) { AuthorCount existing = final.Find( delegate(AuthorCount authcount) { return(authcount.Name == ac.Name); }); if (existing == null) { final.Add(ac); } else { existing.Count += ac.Count; } } reader.Close(); } return(final); }
public static List<AuthorCount> GetAuthorCountForStatus(PostStatus status, string categoryID) { List<AuthorCount> autCounts = new List<AuthorCount>(); List<AuthorCount> final = new List<AuthorCount>(); QueryCommand cmd = new QueryCommand( @"select u.Id, " + DataService.Provider.SqlCountFunction("u.Id") + @" as IdCount, u.ProperName, p.CategoryId from graffiti_Posts AS p inner join graffiti_Users as u on p.CreatedBy = u.Name where p.Status = " + DataService.Provider.SqlVariable("Status") + @" and p.IsDeleted = 0"); if(!String.IsNullOrEmpty(categoryID)) { cmd.Sql += " and p.CategoryId = " + DataService.Provider.SqlVariable("CategoryId"); } cmd.Sql += " group by u.Id, u.ProperName, p.CategoryId"; List<Parameter> parameters = Post.GenerateParameters(); cmd.Parameters.Add(Post.FindParameter(parameters, "Status")).Value = (int)status; if (!String.IsNullOrEmpty(categoryID)) { cmd.Parameters.Add(Post.FindParameter(parameters, "CategoryId")).Value = Convert.ToInt32(categoryID); } using (IDataReader reader = DataService.ExecuteReader(cmd)) { while (reader.Read()) { AuthorCount autCount = new AuthorCount(); autCount.ID = Int32.Parse(reader["Id"].ToString()); autCount.Count = Int32.Parse(reader["IdCount"].ToString()); autCount.Name = reader["ProperName"].ToString(); autCount.CategoryId = Int32.Parse(reader["CategoryId"].ToString()); autCounts.Add(autCount); } List<AuthorCount> filteredPermissions = new List<AuthorCount>(); filteredPermissions.AddRange(autCounts); foreach (AuthorCount ac in autCounts) { if (!RolePermissionManager.GetPermissions(ac.CategoryId, GraffitiUsers.Current).Read) filteredPermissions.Remove(ac); } foreach (AuthorCount ac in filteredPermissions) { AuthorCount existing = final.Find( delegate(AuthorCount authcount) { return authcount.Name == ac.Name; }); if (existing == null) { final.Add(ac); } else { existing.Count += ac.Count; } } reader.Close(); } return final; }