From f60031861acf83179e21d433b624e4fca86c8be7 Mon Sep 17 00:00:00 2001
From: Rickard Liljeberg <rickard@liljeberg.se>
Date: Fri, 16 Jul 2021 16:17:57 +0200
Subject: [PATCH] Support for updating a users name.formatted

---
 .../Protocol/Core2EnterpriseUserExtensions.cs | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Protocol/Core2EnterpriseUserExtensions.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Protocol/Core2EnterpriseUserExtensions.cs
index 69cdaab5..ae9087e0 100644
--- a/Microsoft.SystemForCrossDomainIdentityManagement/Protocol/Core2EnterpriseUserExtensions.cs
+++ b/Microsoft.SystemForCrossDomainIdentityManagement/Protocol/Core2EnterpriseUserExtensions.cs
@@ -813,6 +813,27 @@ private static void PatchName(this Core2EnterpriseUser user, PatchOperation2 ope
                 name.FamilyName = value;
             }
 
+            if
+            (
+                string.Equals(
+                    Microsoft.SCIM.AttributeNames.Formatted,
+                    operation.Path.ValuePath.AttributePath,
+                    StringComparison.OrdinalIgnoreCase)
+            )
+            {
+                value = operation.Value?.Single().Value;
+                if
+                (
+                        value != null
+                    && OperationName.Remove == operation.Name
+                    && string.Equals(value, name.Formatted, StringComparison.OrdinalIgnoreCase)
+                )
+                {
+                    value = null;
+                }
+                name.Formatted = value;
+            }
+
             if (string.IsNullOrWhiteSpace(name.FamilyName) && string.IsNullOrWhiteSpace(name.GivenName))
             {
                 if (nameExisting != null)