예제 #1
0
        private static void PatchMembers(this Core2Group group, PatchOperation operation)
        {
            //path Members expects operation to only contain one item

            group.Members = PatchMembers(group.Members, operation);
            if (operation.Value.Count > 1)
            {
                List <Newtonsoft.Json.Linq.JToken> list = operation.Value.ToList();
                list.RemoveAt(0);
                operation.Value = list;
                group.PatchMembers(operation);
            }
        }
예제 #2
0
        public static void Apply(this Core2Group group, PatchOperation operation)
        {
            if (null == operation)
            {
                return;
            }

            if (null == operation.Path || string.IsNullOrWhiteSpace(operation.Path.AttributePath))
            {
                return;
            }


            OperationValue value;

            switch (operation.Path.AttributePath)
            {
            case AttributeNames.DisplayName:
                value = operation.Value.SingleOrDefault().ToObject <OperationValue>();

                if (OperationName.Remove == operation.Name)
                {
                    if ((null == value) || string.Equals(group.DisplayName, value.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        value = null;
                    }
                    else
                    {
                        break;
                    }
                }

                if (null == value)
                {
                    group.DisplayName = null;
                }
                else
                {
                    group.DisplayName = value.Value;
                }
                break;

            case AttributeNames.Members:
                group.PatchMembers(operation);
                break;

            case AttributeNames.ExternalIdentifier:
                value = operation.Value.SingleOrDefault().ToObject <OperationValue>();

                if (OperationName.Remove == operation.Name)
                {
                    if ((null == value) || string.Equals(group.ExternalIdentifier, value.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        value = null;
                    }
                    else
                    {
                        break;
                    }
                }

                if (null == value)
                {
                    group.ExternalIdentifier = null;
                }
                else
                {
                    group.ExternalIdentifier = value.Value;
                }
                break;

            default:
                break;
            }
        }