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(); }
public async Task RemoveDatasetAsync(int datasetId) { var customDataset = await _customDatasetRepository.GetByIdAsync(datasetId); var result = await _customDatasetRepository.RemoveByIdAsync(datasetId); if (!result) { throw new InvalidDataException($"Can't delete Custom Dataset with id {datasetId} !"); } var dataset = await _datasetRepository.GetByNameAsync(customDataset.Name.ToLower()); await _datasetRepository.RemoveByIdAsync(dataset.Id); await _uow.CommitAsync(); }