private void ProcessRepositoryEvent(RepositoryMonitorEvent Event)
{
var device = (Device)Event.Entity;
string previousUserId = Event.GetPreviousPropertyValue<string>("AssignedUserId");
Event.ExecuteAfterCommit(e =>
{
switch (e.EventType)
{
case RepositoryMonitorEventType.Added:
AddMember(device.AssignedUserId);
break;
case RepositoryMonitorEventType.Modified:
if (device.DeviceBatchId == this.DeviceBatchId)
{
if (device.AssignedUserId != null)
AddMember(device.AssignedUserId);
if (e.ModifiedProperties.Contains("AssignedUserId"))
{
if (previousUserId != null)
RemoveMember(previousUserId, (database) =>
!database.Devices.Any(d => d.DeviceBatchId == this.DeviceBatchId && d.AssignedUserId == previousUserId)
? new string[] { previousUserId }
: null);
}
}
else
{
if (previousUserId != null)
RemoveMember(previousUserId, (database) =>
!database.Devices.Any(d => d.DeviceBatchId == this.DeviceBatchId && d.AssignedUserId == previousUserId)
? new string[] { previousUserId }
: null);
}
break;
case RepositoryMonitorEventType.Deleted:
if (previousUserId != null)
RemoveMember(previousUserId, (database) =>
!database.Devices.Any(d => d.DeviceBatchId == this.DeviceBatchId && d.AssignedUserId == previousUserId)
? new string[] { previousUserId }
: null);
break;
}
});
}