예제 #1
0
        public async Task <CategoryCreateOrEditOutput> GetCategoryForEdit(CategoryGetDto dto)
        {
            Category category;
            bool     editMode = false;

            if (dto.Id.HasValue)
            {
                category = await _repository.GetAsync(dto.Id.Value);

                editMode = true;
            }
            else
            {
                category = new Category();
            }

            CategoryLevelListInput input = new CategoryLevelListInput()
            {
                UseCodeValue  = dto.UseCodeValue,
                SelectedValue = dto.UseCodeValue ? category.Code : category.Id.ToString()
            };

            var categories = await GetLevelCategories(input);

            return(new CategoryCreateOrEditOutput()
            {
                IsEditMode = editMode,
                Category = ObjectMapper.Map <CategoryDto>(category),
                Categories = categories,
                Targets = GetCategroyTargets(category.Target)
            });
        }
예제 #2
0
        public async Task <List <ComboboxItemDto> > GetLevelCategories(CategoryLevelListInput input)
        {
            List <ComboboxItemDto> items = new List <ComboboxItemDto>();
            var categories = await _repository.GetAllListAsync();

            categories = categories.ToList();

            AppendCategroy(0, 1, input, categories, items);

            return(items);
        }
예제 #3
0
        private void AppendCategroy(int pid, int level, CategoryLevelListInput input, List <Category> categories, List <ComboboxItemDto> items)
        {
            var    list  = categories.Where(m => m.ParentId == pid).OrderBy(m => m.SortId);
            string blank = "";

            for (int i = 0; i < level; i++)
            {
                blank += input.Repeat;
            }
            blank += input.Pre;

            foreach (var item in list)
            {
                string value = input.UseCodeValue ? item.Code : item.Id.ToString();
                string text  = blank + item.Name;
                items.Add(new ComboboxItemDto(value, text)
                {
                    IsSelected = value == input.SelectedValue
                });
                AppendCategroy(item.Id, level + 1, input, categories, items);
            }
        }