Beispiel #1
0
        public async Task ToDefinedDatasetAsync(int datasetId)
        {
            var dataset = await GetByIdAsync(datasetId);

            if (dataset.IsDefined)
            {
                throw new InvalidDataException($"Dataset <{dataset.Name}> is already defined!");
            }

            var customDataset = await _customDatasetRepository.GetDatasetByNameAsync(dataset.Name.ToLower());

            var customDatasetValues = await _customDatasetRepository.GetValuesByDatasetIdAsync(customDataset?.Id ?? 0);

            await _customDatasetRepository.RemoveByIdAsync(customDataset.Id);

            var definedDataset = _mapper.Map <DefinedDataset>(dataset);
            await _datasetRepository.ToDefinedDatasetAsync(dataset.Id);

            await _definedDatasetRepository.AddAsync(definedDataset);

            await _definedDatasetRepository.AddValuesAsync(_mapper.Map <IEnumerable <DefinedDatasetValue> >(customDatasetValues)
                                                           .Select(item => { item.Dataset = definedDataset; return(item); }));

            await _uow.CommitAsync();
        }
Beispiel #2
0
        public async Task AddAsync(DefinedDatasetModel definedDatasetModel)
        {
            var definedDataset       = _mapper.Map <DefinedDataset>(definedDatasetModel);
            var dataset              = _mapper.Map <Dataset>(definedDatasetModel);
            var definedDatasetValues = _mapper.Map <IEnumerable <DefinedDatasetValue> >(definedDatasetModel.Values).Select(item => { item.Dataset = definedDataset; return(item); });

            await _definedDatasetRepository.AddAsync(definedDataset);

            await _definedDatasetRepository.AddValuesAsync(definedDatasetValues);

            await _datasetRepository.AddAsync(dataset);

            await _uow.CommitAsync();
        }