// Get Comments for current Entity and Type public List <CommentComplete> GetbyEntityType(string entityId, int type) { // these are where the parents go //List<CommentComplete> topLevelComments = null; List <CommentComplete> allComments = null; Dictionary <int, List <CommentComplete> > children = null; DataProvider.ExecuteCmd(GetConnection, "dbo.Comments_SelectbyEntityType" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@EntityId", entityId); paramCollection.AddWithValue("@TypeId", type); } , map : delegate(IDataReader reader, short set) { CommentComplete com = MapComment <CommentComplete>(reader); int commentId = com.Id; int parentId = com.ParentId; if (children == null) { children = new Dictionary <int, List <CommentComplete> >(); } if (allComments == null) { allComments = new List <CommentComplete>(); } if (!children.ContainsKey(parentId)) { children.Add(parentId, new List <CommentComplete>()); } children[parentId].Add(com); allComments.Add(com); }); if (allComments != null) { foreach (CommentComplete comment in allComments) { if (!children.ContainsKey(comment.Id)) { continue; } List <CommentComplete> newreplies = children[comment.Id]; comment.Replies = newreplies; } return(children[0]); } return(allComments); }
// Get by Id public CommentComplete Get(int id) { CommentComplete com = null; DataProvider.ExecuteCmd(GetConnection, "dbo.Comments_Select" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", id); } , map : delegate(IDataReader reader, short set) { com = MapComment <CommentComplete>(reader); }); return(com); }
// Get All public List <CommentComplete> Get() { CommentComplete com = null; List <CommentComplete> list = new List <CommentComplete>(); DataProvider.ExecuteCmd(GetConnection, "dbo.Comments_SelectAll" , inputParamMapper : null, map : delegate(IDataReader reader, short set) { com = MapComment <CommentComplete>(reader); if (list == null) { list = new List <CommentComplete>(); } list.Add(com); } ); return(list); }