Perf: Save only when user updated

This commit is contained in:
Gary Sharp
2017-03-29 13:00:15 +11:00
parent fdf1bd4bc6
commit 4d6aa18095
3 changed files with 31 additions and 7 deletions
+20 -1
View File
@@ -71,21 +71,40 @@ namespace Disco.Models.Repository
return string.Format("{0} ({1})", this.DisplayName, this.UserId);
}
public void UpdateSelf(User u)
public bool UpdateSelf(User u)
{
var changed = false;
if (!this.UserId.Equals(u.UserId, StringComparison.OrdinalIgnoreCase))
throw new ArgumentException("User Id's do not match", "u");
if (this.Surname != u.Surname)
{
this.Surname = u.Surname;
changed = true;
}
if (this.GivenName != u.GivenName)
{
this.GivenName = u.GivenName;
changed = true;
}
if (this.DisplayName != u.DisplayName)
{
this.DisplayName = u.DisplayName;
changed = true;
}
if (this.EmailAddress != u.EmailAddress)
{
this.EmailAddress = u.EmailAddress;
changed = true;
}
if (this.PhoneNumber != u.PhoneNumber)
{
this.PhoneNumber = u.PhoneNumber;
changed = true;
}
return changed;
}
}
}