Пример #1
0
        public virtual async Task<IScimResponse<ScimGroup>> CreateGroup(ScimGroup group)
        {
            _CanonicalizationService.Canonicalize(group, ServerConfiguration.GetScimTypeDefinition(group.GetType()));

            var validator = await _ResourceValidatorFactory.CreateValidator(group);
            var validationResult = (await validator.ValidateCreateAsync(group)).ToScimValidationResult();

            if (!validationResult)
                return new ScimErrorResponse<ScimGroup>(validationResult.Errors.First());

            group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group);
            
            var groupRecord = await _GroupRepository.CreateGroup(group);

            SetResourceVersion(groupRecord);

            return new ScimDataResponse<ScimGroup>(groupRecord);
        }
Пример #2
0
        public virtual async Task <IScimResponse <ScimGroup> > UpdateGroup(ScimGroup group)
        {
            return(await(await RetrieveGroup(group.Id))
                   .BindAsync <ScimGroup, ScimGroup>(async groupRecord =>
            {
                group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group)
                {
                    Created = groupRecord.Meta.Created,
                    LastModified = groupRecord.Meta.LastModified
                };

                _CanonicalizationService.Canonicalize(group, ServerConfiguration.GetScimTypeDefinition(group.GetType()));

                var validator = await _ResourceValidatorFactory.CreateValidator(group);
                var validationResult = (await validator.ValidateUpdateAsync(group, groupRecord)).ToScimValidationResult();

                if (!validationResult)
                {
                    return new ScimErrorResponse <ScimGroup>(validationResult.Errors.First());
                }

                SetResourceVersion(group);

                // if both versions are equal, bypass persistence
                if (group.Meta.Version.Equals(groupRecord.Meta.Version))
                {
                    return new ScimDataResponse <ScimGroup>(groupRecord);
                }

                var updatedGroup = await _GroupRepository.UpdateGroup(group);

                // set version of updated entity returned by repository
                SetResourceVersion(updatedGroup);

                return new ScimDataResponse <ScimGroup>(updatedGroup);
            }));
        }
Пример #3
0
        public virtual async Task <IScimResponse <ScimGroup> > CreateGroup(ScimGroup group)
        {
            _CanonicalizationService.Canonicalize(group, ServerConfiguration.GetScimTypeDefinition(group.GetType()));

            var validator = await _ResourceValidatorFactory.CreateValidator(group);

            var validationResult = (await validator.ValidateCreateAsync(group)).ToScimValidationResult();

            if (!validationResult)
            {
                return(new ScimErrorResponse <ScimGroup>(validationResult.Errors.First()));
            }

            group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group);

            var groupRecord = await _GroupRepository.CreateGroup(group);

            SetResourceVersion(groupRecord);

            return(new ScimDataResponse <ScimGroup>(groupRecord));
        }
Пример #4
0
        public virtual async Task<IScimResponse<ScimGroup>> UpdateGroup(ScimGroup group)
        {
            return await (await RetrieveGroup(group.Id))
                .BindAsync<ScimGroup, ScimGroup>(async groupRecord =>
                {
                    group.Meta = new ResourceMetadata(ScimConstants.ResourceTypes.Group)
                    {
                        Created = groupRecord.Meta.Created,
                        LastModified = groupRecord.Meta.LastModified
                    };

                    _CanonicalizationService.Canonicalize(group, ServerConfiguration.GetScimTypeDefinition(group.GetType()));

                    var validator = await _ResourceValidatorFactory.CreateValidator(group);
                    var validationResult = (await validator.ValidateUpdateAsync(group, groupRecord)).ToScimValidationResult();

                    if (!validationResult)
                        return new ScimErrorResponse<ScimGroup>(validationResult.Errors.First());

                    SetResourceVersion(group);

                    // if both versions are equal, bypass persistence
                    if (string.Equals(group.Meta.Version, groupRecord.Meta.Version))
                        return new ScimDataResponse<ScimGroup>(groupRecord);

                    var updatedGroup = await _GroupRepository.UpdateGroup(group);

                    // set version of updated entity returned by repository
                    SetResourceVersion(updatedGroup);

                    return new ScimDataResponse<ScimGroup>(updatedGroup);
                });
        }