public async Task Create_DataDictionaryDetail_Test()
        {
            var input = new CreateDataDictionaryDto
            {
                Name        = "外贸",
                Description = "I-进口,E-出口,C-国产"
            };
            var master = await _dictionaryAppService.CreateAsync(input);

            master.ShouldNotBeNull();

            var inputC = new CreateDataDictionaryDetailDto
            {
                Pid   = master.Id,
                Label = "国产",
                Value = "G",
                Sort  = 1
            };

            (await _dictionaryDetailAppService.CreateAsync(inputC)).ShouldNotBeNull();

            var inputI = new CreateDataDictionaryDetailDto
            {
                Pid   = master.Id,
                Label = "进口",
                Value = "I",
                Sort  = 2
            };

            (await _dictionaryDetailAppService.CreateAsync(inputI)).ShouldNotBeNull();

            var inputE = new CreateDataDictionaryDetailDto
            {
                Pid   = master.Id,
                Label = "出口",
                Value = "E",
                Sort  = 3
            };

            (await _dictionaryDetailAppService.CreateAsync(inputE)).ShouldNotBeNull();

            var items = (await _dictionaryDetailAppService.GetListAsync(new GetDictionaryDetailInputDto
            {
                SkipCount = 0,
                Sorting = "sort desc",
                MaxResultCount = 20,
                Pid = master.Id
            })).Items;

            items.FirstOrDefault().ShouldNotBeNull();
            items.Count.ShouldBeGreaterThan(0);
            items.FirstOrDefault().Label.ShouldBe("出口");
        }
예제 #2
0
        public async Task <ApiResult> CreateDetailAsync(CreateDataDictionaryDetailDto input)
        {
            var entity = await _dataDictionaryRepository.Include(e => e.DataDictionaryDetails).Where(e => e.Id == input.Id).FirstOrDefaultAsync();

            if (entity == null)
            {
                return(ApiResult.Error($"{_localizer["DataExistence"]}"));
            }

            entity.AddDataDictionaryDetail(new DataDictionaryDetail(_guidGenerator.Create(), input.Label, input.Value, input.Sort));

            await _dataDictionaryRepository.UpdateAsync(entity);

            return(ApiResult.Ok());
        }