Example #1
0
        //DRY Principle

        public List <WikiPage> GetWikePages(Action <SqlParameterCollection> paramMapper, string procName)
        {
            List <WikiPage>             pages          = null;
            List <WikiPage>             top            = null;
            Dictionary <int, WikiPage>  dic            = null;
            List <WikiPageSpace>        wikiPageSpaces = null;
            Dictionary <int, WikiSpace> wikiSpaces     = null;


            DataProvider.ExecuteCmd(GetConnection, procName
                                    , inputParamMapper : paramMapper,
                                    map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    if (pages == null)
                    {
                        pages = new List <WikiPage>();
                    }

                    if (dic == null)
                    {
                        dic = new Dictionary <int, WikiPage>();
                    }

                    if (top == null)
                    {
                        top = new List <WikiPage>();
                    }

                    ProcessWikiPageData(reader, pages, dic, top);
                }
                else if (set == 1)
                {
                    WikiPageSpace wps = MapWikPageSpaces(reader);

                    if (wikiPageSpaces == null)
                    {
                        wikiPageSpaces = new List <WikiPageSpace>();
                    }

                    wikiPageSpaces.Add(wps);
                }
                else if (set == 2)
                {
                    if (wikiSpaces == null)
                    {
                        wikiSpaces = new Dictionary <int, WikiSpace>();
                    }

                    ProcessWikiSpaceData(reader, wikiSpaces);
                }
                else if (set == 3)
                {
                    WikiTags wt       = new WikiTags();
                    int startingIndex = 0;


                    wt.WikiId  = reader.GetSafeInt32(startingIndex++);
                    wt.TagId   = reader.GetSafeInt32(startingIndex++);
                    wt.TagName = reader.GetSafeString(startingIndex++);

                    WikiPage parent = dic[wt.WikiId];
                    if (parent.WikiTags == null)
                    {
                        parent.WikiTags = new List <WikiTags>();
                    }
                    parent.WikiTags.Add(wt);
                }
            }
                                    );

            LinkPagesToSpaces(wikiPageSpaces, pages, wikiSpaces);

            LinkToTop(dic, top);

            return(top);
        }
Example #2
0
        // Wiki by ID
        public WikiPage GetWiki(int id)
        {
            WikiPage             item           = null;
            List <WikiPageSpace> wikiPageSpaces = null;

            WikiSpace ws;

            DataProvider.ExecuteCmd(GetConnection, "dbo.WikiPages_SelectByIdv2"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
                //model binding
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    item = new WikiPage();
                    int startingIndex = 0;     // startingOrdinal

                    item.Id                   = reader.GetSafeInt32(startingIndex++);
                    item.Title                = reader.GetSafeString(startingIndex++);
                    item.URL                  = reader.GetSafeString(startingIndex++);
                    item.PublishDate          = reader.GetSafeDateTime(startingIndex++);
                    item.Language             = reader.GetSafeInt32(startingIndex++);
                    item.LastModifiedByUserId = reader.GetSafeString(startingIndex++);
                    item.ParentId             = reader.GetSafeInt32(startingIndex++);
                }
                else if (set == 1)
                {
                    WikiPageSpace wps = new WikiPageSpace();
                    int startingIndex = 0;


                    wps.WikiPageId  = reader.GetSafeInt32(startingIndex++);
                    wps.WikiSpaceId = reader.GetSafeInt32(startingIndex++);

                    if (wikiPageSpaces == null)
                    {
                        wikiPageSpaces = new List <WikiPageSpace>();
                    }
                    wikiPageSpaces.Add(wps);
                }
                else if (set == 2)
                {
                    ws = new WikiSpace();
                    int startingIndex = 0;

                    ws.Id       = reader.GetSafeInt32(startingIndex++);
                    ws.Title    = reader.GetSafeString(startingIndex++);
                    ws.ParentId = reader.GetSafeInt32(startingIndex++);

                    if (item != null)
                    {
                        if (wikiPageSpaces != null)
                        {
                            foreach (WikiPageSpace wikiPageSpace in wikiPageSpaces)
                            {
                                if (item.Id == wikiPageSpace.WikiPageId && ws.Id == wikiPageSpace.WikiSpaceId)
                                {
                                    if (item.WikiSpaces == null)
                                    {
                                        item.WikiSpaces = new List <WikiSpace>();
                                    }
                                    item.WikiSpaces.Add(ws);
                                }
                            }
                        }
                    }
                }
                else if (set == 3)
                {
                    WikiTags wt       = new WikiTags();
                    int startingIndex = 0;


                    wt.WikiId  = reader.GetSafeInt32(startingIndex++);
                    wt.TagId   = reader.GetSafeInt32(startingIndex++);
                    wt.TagName = reader.GetSafeString(startingIndex++);

                    if (item.WikiTags == null)
                    {
                        item.WikiTags = new List <WikiTags>();
                    }
                    item.WikiTags.Add(wt);
                }
            }

                                    );

            return(item);
        }