Exemplo n.º 1
0
        public List<Blog> GetByTagName(string tagName, int status)
        {
            List<Blog> list = null;
            Dictionary<int, List<Tags>> dictionary = null;
            Dictionary<int, List<CoverPhotos>> photoDictionary = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Blogs_SelectByTagName_v2"
               , inputParamMapper: delegate(SqlParameterCollection paramCollection)
               {
                   paramCollection.AddWithValue("@Name", tagName);
                   paramCollection.AddWithValue("@Status", status);
               }
               , map: delegate(IDataReader reader, short set)
               {
                   if (set == 0)
                   {
                       Blog p = MapBlog(reader);

                       if (list == null)
                       {
                           list = new List<Blog>();
                       }

                       list.Add(p);
                   }
                   else if (set == 1)
                   {
                       int startingIndex = 0;

                       int ID = reader.GetSafeInt32(startingIndex++);
                       string Name = reader.GetSafeString(startingIndex++);
                       bool IsActive = reader.GetSafeBool(startingIndex++);
                       int blogID = reader.GetSafeInt32(startingIndex++);

                       if (dictionary == null)
                       {
                           dictionary = new Dictionary<int, List<Tags>>();
                       }

                       if (!dictionary.ContainsKey(blogID))
                       {
                           dictionary[blogID] = new List<Tags>();

                       }

                       dictionary[blogID].Add(MapTag(reader));

                   }
                   else if (set == 2)
                   {
                       int startingIndex = 0;

                       int Id = reader.GetSafeInt32(startingIndex++);
                       string Path = reader.GetSafeString(startingIndex++);
                       int fileType = reader.GetSafeInt32(startingIndex++);
                       int blogId = reader.GetSafeInt32(startingIndex++);

                       if (photoDictionary == null)
                       {
                           photoDictionary = new Dictionary<int, List<CoverPhotos>>();
                       }

                       if (!photoDictionary.ContainsKey(blogId))
                       {
                           photoDictionary[blogId] = new List<CoverPhotos>();
                       }

                       photoDictionary[blogId].Add(MapCoverPhotos(reader));
                   }
               }
               );

            //loop thru list of blogs and if the dictionary had an item in it with the same key as the blog id, asssign the value to the current blog.
            foreach (KeyValuePair<int, List<Tags>> pair in dictionary)
            {

                Blog foundBlog = new Blog();

                if (list == null)
                {
                    foundBlog = null;
                }
                else
                {
                    foundBlog = list.Find(delegate(Blog bID)
                    {
                        if (bID.ID == pair.Key)
                        {
                            return true;
                        }
                        return false;
                    });
                }

                if (foundBlog == null)
                {
                    continue;
                }

                foundBlog.Tags = pair.Value;

            }
            foreach (KeyValuePair<int, List<CoverPhotos>> pair in photoDictionary)
            {

                Blog foundBlog = new Blog();

                if (list == null)
                {
                    foundBlog = null;
                }
                else
                {
                    foundBlog = list.Find(delegate(Blog bID)
                    {
                        if (bID.ID == pair.Key)
                        {
                            return true;
                        }
                        return false;
                    });
                }

                if (foundBlog == null)
                {
                    continue;
                }

                foundBlog.CoverPhotos = pair.Value;

            }

            return list;
        }
Exemplo n.º 2
0
        private static Blog MapBlog(IDataReader reader)
        {
            Blog p = new Blog();
            ////bool isBlogPostData = false;
            //if (reader.FieldCount == 12)
            //{
            //    p = new Blog();
            //}
            //else
            //{
            //    p = new Blog();
            //    isBlogPostData = true;
            //}

            int startingIndex = 0;

            p.ID = reader.GetSafeInt32(startingIndex++);
            p.Title = reader.GetSafeString(startingIndex++);
            p.Content = reader.GetSafeString(startingIndex++);
            p.LiveDate = reader.GetSafeDateTime(startingIndex++);
            p.Status = reader.GetSafeInt32(startingIndex++);
            p.MetaData = reader.GetSafeString(startingIndex++);
            p.PathName = reader.GetSafeString(startingIndex++);
            string UserID = reader.GetSafeString(startingIndex++);
            p.DateAdded = reader.GetSafeDateTime(startingIndex++);
            p.DateModified = reader.GetSafeDateTime(startingIndex++);
            p.LanguageCode = reader.GetSafeString(startingIndex++);
            p.CountOfComments = reader.GetSafeInt32(startingIndex++);
            //p.Preview = reader.GetSafeString(startingIndex++);

            //here instead of Blog use the new Domain Object

            p.FirstName = reader.GetSafeString(startingIndex++);
            p.LastName = reader.GetSafeString(startingIndex++);
            p.Preview = reader.GetSafeString(startingIndex++);
            //DO NOT INCLUDE HERE p.CountOfComments = reader.GetSafeInt32(startingIndex++);
            //in here read out the extra properties

            return p;
        }
Exemplo n.º 3
0
        public List<Blog> GetBlogsByStatus(int Status)
        {
            List<Blog> list = null;
            Dictionary<int, List<Tags>> dictionary = null;
            DataProvider.ExecuteCmd(GetConnection, "dbo.Blogs_SelectByStatus_v2"
               , inputParamMapper: delegate(SqlParameterCollection paramCollection)
               {

                   paramCollection.AddWithValue("@Status", Status);

               } //
                , map: delegate(IDataReader reader, short set)
                {
                    if (set == 0)
                    {
                        Blog p = MapBlog(reader);

                        if (list == null)
                        {
                            list = new List<Blog>();
                        }

                        list.Add(p);
                    }
                    else if (set == 1)
                    {
                        int startingIndex = 0;

                        int ID = reader.GetSafeInt32(startingIndex++);
                        string Name = reader.GetSafeString(startingIndex++);
                        bool IsActive = reader.GetSafeBool(startingIndex++);
                        int blogID = reader.GetSafeInt32(startingIndex++);

                        if (dictionary == null)
                        {
                            dictionary = new Dictionary<int, List<Tags>>();
                        }

                        if (!dictionary.ContainsKey(blogID))
                        {
                            dictionary[blogID] = new List<Tags>();

                            //dictionary[blogID].Add(ID);
                            //dictionary[blogID].Add(Name);
                            //dictionary[blogID].Add(IsActive);
                        }

                        dictionary[blogID].Add(MapTag(reader));
                    }

                }
               );
            foreach (KeyValuePair<int, List<Tags>> pair in dictionary)
            {

                Blog foundBlog = new Blog();
                foundBlog = list.Find(delegate(Blog bID)
                {
                    if (bID.ID == pair.Key)
                    {
                        return true;
                    }
                    return false;
                });

                if (foundBlog == null)
                {
                    continue;
                }

                foundBlog.Tags = pair.Value;

            }

            return list;
        }