AvailableNameFormats { get; set; }
}
diff --git a/Gibbon.Git.Server/Models/UserModel.cs b/Gibbon.Git.Server/Models/UserModel.cs
index 578c60f5..b0517d13 100644
--- a/Gibbon.Git.Server/Models/UserModel.cs
+++ b/Gibbon.Git.Server/Models/UserModel.cs
@@ -1,4 +1,6 @@
-namespace Gibbon.Git.Server.Models;
+using Gibbon.Git.Server.Data.Entities;
+
+namespace Gibbon.Git.Server.Models;
public class UserModel
{
@@ -8,14 +10,43 @@ public class UserModel
public string Surname { get; set; }
public string Email { get; set; }
- public string DisplayName => !string.IsNullOrWhiteSpace(GivenName) || !string.IsNullOrWhiteSpace(Surname)
- ? $"{Surname}, {GivenName}".Trim(' ', ',')
- : Username;
+ public string DisplayName => GetDisplayName(NameFormat.LastCommaFirst);
///
/// This is the name we'd sort users by
///
- public string SortName => !string.IsNullOrWhiteSpace(Surname) || !string.IsNullOrWhiteSpace(GivenName)
- ? $"{Surname}{GivenName}"
- : Username;
+ public string SortName => GetSortName(NameFormat.LastCommaFirst);
+
+ public string GetDisplayName(NameFormat format)
+ {
+ if (string.IsNullOrWhiteSpace(GivenName) && string.IsNullOrWhiteSpace(Surname))
+ {
+ return Username;
+ }
+
+ return format switch
+ {
+ NameFormat.FirstLast => $"{GivenName} {Surname}".Trim(),
+ NameFormat.LastCommaFirst => $"{Surname}, {GivenName}".Trim(' ', ','),
+ NameFormat.LastFirst => $"{Surname} {GivenName}".Trim(),
+ _ => $"{Surname}, {GivenName}".Trim(' ', ',')
+ };
+ }
+
+ public string GetSortName(NameFormat format)
+ {
+ if (string.IsNullOrWhiteSpace(Surname) && string.IsNullOrWhiteSpace(GivenName))
+ {
+ return Username;
+ }
+
+ return format switch
+ {
+ NameFormat.FirstLast => $"{GivenName}{Surname}",
+ NameFormat.LastCommaFirst => $"{Surname}{GivenName}",
+ NameFormat.LastFirst => $"{Surname}{GivenName}",
+ _ => $"{Surname}{GivenName}"
+ };
+ }
}
+
diff --git a/Gibbon.Git.Server/Views/Account/Settings.cshtml b/Gibbon.Git.Server/Views/Account/Settings.cshtml
index 03806402..ac32e7f1 100644
--- a/Gibbon.Git.Server/Views/Account/Settings.cshtml
+++ b/Gibbon.Git.Server/Views/Account/Settings.cshtml
@@ -20,6 +20,12 @@
+
+ @Html.LabelFor(m => m.PreferredNameFormat)
+ @Html.DropDownListFor(m => m.PreferredNameFormat, Model.AvailableNameFormats, new { @class = "medium" })
+
+
+