Esempio n. 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();
        }