/// <summary>
 /// Creates the category list if input is invalid.
 /// </summary>
 /// <param name="list">The list.</param>
 private void CreateCategoryList(List<PhpCategoryEntity> list)
 {
     var categoryEntity = new PhpCategoryEntity
                              {
                                  ID = "1",
                                  Description = "General",
                                  ParentID = "0"
                              };
     list.Add(categoryEntity);
 }
        /// <summary>
        /// Parses the categories.
        /// </summary>
        /// <param name="categoryList">The category list.</param>
        /// <returns></returns>
        private List<PhpCategoryEntity> ParseCategories(string categoryList)
        {
            var list = new List<PhpCategoryEntity>();

            if (categoryList.Trim().Contains("|"))
            {
                var categories = categoryList.Split('|');
                if ((categories.Length) % 3 == 0)
                {
                    int i = 0;
                    while (i + 3 <= categories.Length)
                    {
                        // ID | Description | Depth
                        //1|General|0|
                        //2|News|0|
                        //6|Announcements|1|
                        //7|Events|1|
                        //8|Miscellaneous|1|
                        //3|Humour|0|
                        //9|General Humour|1|
                        //10|Tasteless Humour|1|
                        //4|Technology|0|
                        //5|Writing|0|
                        //11|Quotations|1|
                        //13|Rantings|1|
                        //12|Science Stuff|0|

                        var categoryEntity = new PhpCategoryEntity
                                                 {
                                                     ID = categories[i],
                                                     Description = categories[i + 1],
                                                     Depth = Convert.ToInt32(categories[i + 2])
                                                 };
                        list.Add(categoryEntity);
                        i = i + 3;
                    }
                }
                else
                {
                    CreateCategoryList(list);
                }
            }
            else
            {
                CreateCategoryList(list);
            }

            var newList = new List<PhpCategoryEntity>();

            for (int i = 0; i < list.Count; i++)
            {
                var entity = new PhpCategoryEntity
                                 {
                                     ID = list[i].ID,
                                     Description = list[i].Description
                                 };

                // Depth calculator
                int currentDepth;
                int previousDepth;
                if (i == 0)
                {
                    previousDepth = currentDepth = 0;
                }
                else
                {
                    previousDepth = list[i - 1].Depth;
                    currentDepth = list[i].Depth;
                }
                if (previousDepth < currentDepth)
                {
                    entity.ParentID = list[i - 1].ID;
                }
                else if (previousDepth == currentDepth && currentDepth != 0)
                {
                    entity.ParentID = newList[i - 1].ParentID;
                }
                else
                {
                    entity.ParentID = "0";
                }
                newList.Add(entity);
            }

            return newList;
        }
 /// <summary>
 /// Converts the category entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 private WpCategoryEntity ConvertCategoryEntity(PhpCategoryEntity entity)
 {
     var wpCategoryEntity = new WpCategoryEntity();
     try
     {
         wpCategoryEntity.ID = Convert.ToInt32(entity.ID);
         wpCategoryEntity.Description = entity.Description;
         wpCategoryEntity.ParentID = Convert.ToInt32(entity.ParentID);
     }
     catch
     {
         wpCategoryEntity.ID = 1;
         wpCategoryEntity.Description = "General";
         wpCategoryEntity.ParentID = 0;
     }
     return wpCategoryEntity;
 }