예제 #1
0
        public override async Task <TemplateCategoryViewModel> GetByCode(string code)
        {
            if (HID.CacheClient.ContainsKey(code) == true)
            {
                return((TemplateCategoryViewModel)HID.CacheClient[code]);
            }
            TemplateCategoryViewModel result = await base.GetByCode(code);

            HID.Add(code, result);
            return(result);
        }
        void WriteCategory(TemplateCategoryViewModel category)
        {
            writer.WriteStartElement("Category");

            writer.WriteAttributeString("id", GetAttributeValueOrDefault(category.Id, "id"));
            writer.WriteAttributeString("name", GetAttributeValueOrDefault(category.Name, "Category"));

            foreach (TemplateCategoryViewModel childCategory in category.GetChildCategories())
            {
                WriteCategory(childCategory);
            }

            writer.WriteEndElement();
        }
        static void MarkNewCategories(TemplateCategoryViewModel category, IEnumerable <TemplateCategoryViewModel> categories)
        {
            var existingTopLevelCategory = category.FindExistingCategory(categories);

            if (existingTopLevelCategory != null)
            {
                foreach (var secondLevelCategory in category.GetChildCategories())
                {
                    var existingSecondLevelCategory = secondLevelCategory.FindExistingCategory(
                        existingTopLevelCategory.Categories);
                    if (existingSecondLevelCategory != null)
                    {
                        foreach (var newThirdLevelCategory in secondLevelCategory.GetChildCategories())
                        {
                            var existingThirdLevelCategory = newThirdLevelCategory.FindExistingCategory(
                                existingSecondLevelCategory.Categories);
                            if (existingThirdLevelCategory != null)
                            {
                                // Category exists.
                            }
                            else
                            {
                                newThirdLevelCategory.IsNew = true;
                            }
                        }
                    }
                    else
                    {
                        secondLevelCategory.IsNew = true;
                    }
                }
            }
            else
            {
                category.IsNew = true;
            }
        }
        static TemplateCategory FindExistingCategory(this TemplateCategoryViewModel category, IEnumerable <TemplateCategoryViewModel> categories)
        {
            var matchedCategory = categories.FirstOrDefault(existingCategory => IsMatch(category.Category, existingCategory.Category));

            return(matchedCategory?.Category);
        }