Example #1
0
        public async Task <DatasetDto> GetDatasetByStudyIdAndDatasetIdAsync(int studyId, int datasetId)
        {
            var studyFromDb = await _studyModelService.GetForDatasetsAsync(studyId);

            var studyDatasetRelation = studyFromDb.StudyDatasets.FirstOrDefault(sd => sd.DatasetId == datasetId);

            if (studyDatasetRelation == null)
            {
                throw NotFoundException.CreateForEntity("StudyDataset", datasetId);
            }

            var datasetDto = _mapper.Map <DatasetDto>(studyDatasetRelation.Dataset);

            await DecorateDtoStudySpecific(_userService, studyFromDb, datasetDto.Permissions);

            return(datasetDto);
        }
Example #2
0
        public async Task <DatasetDto> UpdateStudySpecificDatasetAsync(int studyId, int datasetId, DatasetCreateUpdateInputBaseDto updatedDataset)
        {
            DatasetUtils.PerformUsualTestForPostedDatasets(updatedDataset);

            var studyFromDb = await _studyModelService.GetForDatasetsAsync(studyId, UserOperation.Study_AddRemove_Dataset);

            var datasetFromDb = GetStudySpecificDatasetOrThrow(studyFromDb, datasetId);

            DatasetUtils.UpdateDatasetBasicDetails(datasetFromDb, updatedDataset);

            Validate(datasetFromDb);

            await _db.SaveChangesAsync();

            var datasetDto = _mapper.Map <DatasetDto>(datasetFromDb);

            await DecorateDtoStudySpecific(_userService, studyFromDb, datasetDto.Permissions);

            return(datasetDto);
        }