private async Task <UpdateResponse> UpdateAttribute(RepresentationAttribute source, RepresentationAttribute target, string resourceType) { var result = new UpdateResponse(); var complexSource = source as ComplexRepresentationAttribute; var complexTarget = target as ComplexRepresentationAttribute; if (complexTarget != null) { var schemaAttribute = complexTarget.SchemaAttribute; if (schemaAttribute.MultiValued) { // Check mutability if (schemaAttribute.Mutability == Common.Constants.SchemaAttributeMutability.Immutable) { if (complexTarget.CompareTo(complexSource) != 0) { result.SetError(_errorResponseFactory.CreateError(string.Format(ErrorMessages.TheImmutableAttributeCannotBeUpdated, schemaAttribute.Name), HttpStatusCode.BadRequest, Common.Constants.ScimTypeValues.Mutability)); return(result); } } // Check uniqueness if (schemaAttribute.Uniqueness == Common.Constants.SchemaAttributeUniqueness.Server) { var filter = _filterParser.Parse(complexTarget.FullPath); var uniqueAttrs = await _representationStore.SearchValues(resourceType, filter); if (uniqueAttrs.Any()) { if (uniqueAttrs.Any(a => a.CompareTo(complexTarget) == 0)) { result.SetError(_errorResponseFactory.CreateError( string.Format(ErrorMessages.TheAttributeMustBeUnique, complexTarget.SchemaAttribute.Name), HttpStatusCode.BadRequest, Common.Constants.ScimTypeValues.Uniqueness)); return(result); } } } } complexSource.Values = complexTarget.Values; return(result); } // Check mutability if (target.SchemaAttribute.Mutability == Common.Constants.SchemaAttributeMutability.Immutable) { if (source.CompareTo(target) != 0) { result.SetError(_errorResponseFactory.CreateError(string.Format(ErrorMessages.TheImmutableAttributeCannotBeUpdated, target.SchemaAttribute.Name), HttpStatusCode.BadRequest, Common.Constants.ScimTypeValues.Mutability)); return(result); } } // Check uniqueness if (target.SchemaAttribute.Uniqueness == Common.Constants.SchemaAttributeUniqueness.Server) { var filter = _filterParser.Parse(target.FullPath); var uniqueAttrs = await _representationStore.SearchValues(resourceType, filter); if (uniqueAttrs.Any()) { if (uniqueAttrs.Any(a => a.CompareTo(target) == 0)) { result.SetError(_errorResponseFactory.CreateError( string.Format(ErrorMessages.TheAttributeMustBeUnique, target.SchemaAttribute.Name), HttpStatusCode.BadRequest, Common.Constants.ScimTypeValues.Uniqueness)); return(result); } } } // Assign the values AssignValues(source, target); return(result); }