public static IList<CategoryView> PrepareCategoryViewModels(this IList<Category> categories, 
            IPictureService pictureService, SystemSetting sysSetting, int? pictureSize = null)
        {
            IList<CategoryView> results = new List<CategoryView>();

            foreach (var item in categories)
            {
                CategoryView view = new CategoryView
                {
                    Id = item.Id,
                    Name = item.Name
                };

                // Prepare the picture model
                if (pictureSize.HasValue && pictureService != null && sysSetting != null)
                {
                    //picture
                    var picture = pictureService.GetPicturesByProductId(item.Id, 1).FirstOrDefault();
                    int imageSize = pictureSize > 0 ? pictureSize.Value : sysSetting.DefaultThumbPicSize;

                    // PictureModel
                    PictureModel pictureModel = new PictureModel
                    {
                        ImageUrl = pictureService.GetPictureUrl(picture, imageSize),
                        FullSizeImageUrl = pictureService.GetPictureUrl(picture),
                        Title = string.Format("Show detail for {0}", item.Name),
                        AlternateText = string.Format("Image of {0}", item.Name)
                    };
                    view.PictureModel = pictureModel;
                }
                results.Add(view);
            }
            return results;
        }
        protected virtual IList<CategoryView> PrepareCategoryViewsByPath(int? rootCategoryId, 
            IList<int> loadSubCategoriesInIds, bool isLoadPicture)
        {
            var result = new List<CategoryView>();
            foreach (var category in _cateService.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {
                var categoryModel = new CategoryView()
                {
                    Id = category.Id,
                    Name = category.Name
                };

                if (isLoadPicture)
                {
                    //picture
                    var picture = _pictureService.GetPictureById(category.PictureId);
                    int imageSize = _sysSetting.DefaultGridPicSize;

                    // PictureModel
                    PictureModel pictureModel = new PictureModel
                    {
                        ImageUrl = _pictureService.GetPictureUrl(picture, imageSize),
                        FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                        Title = string.Format("Show detail for {0}", category.Name),
                        AlternateText = string.Format("Image of {0}", category.Name)
                    };
                    categoryModel.PictureModel = pictureModel;
                }

                //load subcategories?
                if (loadSubCategoriesInIds != null && loadSubCategoriesInIds.Contains(category.Id))
                {
                    var subCategories = PrepareCategoryViewsByPath(category.Id, loadSubCategoriesInIds, isLoadPicture);
                    categoryModel.SubCategories = subCategories;
                }
                result.Add(categoryModel);
            }
            return result;
        }