예제 #1
0
        public override MaterialTypeDTO GetById(int?id)
        {
            var dto = base.GetById(id);

            if (dto != null)
            {
                var categoryDTO = MaterialCategoryService.GetById(dto.CategoryId);
                var typeConfigs = MaterialTypeConfigRepository.Find(x => x.MaterialTypeId == id).ToDictionary(x => x.ConfigKey);
                dto.Configs = categoryDTO.Configs.OrderBy(x => x.Sort).Select(x => new MaterialTypeConfigDTO()
                {
                    ConfigKey          = x.ConfigKey,
                    ConfigKeyDesc      = x.ConfigKeyDesc,
                    ConfigValueType    = x.ConfigValueType,
                    ConfigDefaultValue = typeConfigs.ContainsKey(x.ConfigKey) ? typeConfigs[x.ConfigKey].ConfigDefaultValue : null,
                    MaterialTypeId     = dto.Id,
                    Remark             = x.Remark,
                    Sort = x.Sort
                }).ToList();
            }
            return(dto);
        }
예제 #2
0
        public override PageResult <MaterialTypeDTO> Search(SearchArgs <MaterialType> searchArgs)
        {
            var result = base.Search(searchArgs);

            foreach (var item in result.Items)
            {
                var typeConfigs = MaterialTypeConfigRepository.Find(x => x.MaterialTypeId == item.Id).OrderBy(x => x.Sort);
                var categoryDTO = MaterialCategoryService.GetById(item.CategoryId);
                item.Configs = categoryDTO.Configs.Select(x => new MaterialTypeConfigDTO()
                {
                    ConfigKey          = x.ConfigKey,
                    ConfigKeyDesc      = x.ConfigKeyDesc,
                    ConfigValueType    = x.ConfigValueType,
                    ConfigDefaultValue = typeConfigs.FirstOrDefault(y => y.ConfigKey == x.ConfigKey) == null ? null :
                                         typeConfigs.FirstOrDefault(y => y.ConfigKey == x.ConfigKey).ConfigDefaultValue,
                    MaterialTypeId = item.Id,
                    Remark         = x.Remark,
                    Sort           = x.Sort
                }).OrderBy(x => x.Sort).ToList();
            }
            return(result);
        }