public async Task <IEnumerable <DatasetDto> > GetDatasetsForStudyAsync(int studyId)
        {
            var studyFromDb = await _studyModelService.GetForDatasetsAsync(studyId);

            if (studyFromDb.StudyDatasets == null)
            {
                throw NotFoundException.CreateForEntityCustomDescr("StudyDatasets", $"studyId {studyId}");
            }

            var datasetDtos = _mapper.Map <IEnumerable <DatasetDto> >(studyFromDb.StudyDatasets);

            return(datasetDtos);
        }
Exemple #2
0
        public async Task <StudyParticipantDto> RemoveAsync(int studyId, int userId, string roleName)
        {
            List <CloudResourceOperationDto> updateOperations = null;

            try
            {
                var studyFromDb = await GetStudyForParticipantOperation(studyId, roleName);

                if (roleName == StudyRoles.StudyOwner)
                {
                    throw new ArgumentException($"The Study Owner role cannot be deleted");
                }

                var studyParticipantFromDb = studyFromDb.StudyParticipants.FirstOrDefault(p => p.UserId == userId && p.RoleName == roleName);

                if (studyParticipantFromDb == null)
                {
                    throw NotFoundException.CreateForEntityCustomDescr("StudyParticipant", $"studyId: {studyId}, userId: {userId}, roleName: {roleName}");
                }

                studyFromDb.StudyParticipants.Remove(studyParticipantFromDb);

                await CreateRoleUpdateOperationsAsync(studyParticipantFromDb.StudyId);

                await _db.SaveChangesAsync();

                return(_mapper.Map <StudyParticipantDto>(studyParticipantFromDb));
            }
            catch (Exception ex)
            {
                if (updateOperations != null)
                {
                    foreach (var curOperation in updateOperations)
                    {
                        await _cloudResourceOperationUpdateService.AbortAndAllowDependentOperationsToRun(curOperation.Id, ex.Message);
                    }
                }


                if (ex is ForbiddenException)
                {
                    throw;
                }

                throw new Exception($"Remove participant failed: {ex.Message}", ex);
            }
        }