Disco.Services.Documents.ManagedGroups.DocumentTemplateUsersManagedGroup.ProcessDeviceAssignmentRepositoryEvent C# (CSharp) Method

ProcessDeviceAssignmentRepositoryEvent() private method

private ProcessDeviceAssignmentRepositoryEvent ( RepositoryMonitorEvent Event ) : void
Event RepositoryMonitorEvent
return void
        private void ProcessDeviceAssignmentRepositoryEvent(RepositoryMonitorEvent Event)
        {
            var device = (Device)Event.Entity;
            var deviceSerialNumber = device.SerialNumber;
            bool relevantDevice;

            if (Configuration.FilterBeginDate.HasValue)
            {
                relevantDevice = Event.Database.Devices
                    .Where(d => d.SerialNumber == deviceSerialNumber && d.DeviceAttachments.Any(ja => ja.DocumentTemplateId == this.DocumentTemplateId && ja.Timestamp >= Configuration.FilterBeginDate))
                    .Any();
            }
            else
            {
                relevantDevice = Event.Database.Devices
                    .Where(d => d.SerialNumber == deviceSerialNumber && d.DeviceAttachments.Any(ja => ja.DocumentTemplateId == this.DocumentTemplateId))
                    .Any();
            }

            if (relevantDevice)
            {
                var deviceCurrentAssignedUserId = device.AssignedUserId;
                var devicePreviousAssignedUserId = Event.GetPreviousPropertyValue<string>("AssignedUserId");

                Event.ExecuteAfterCommit(e =>
                {
                    if (devicePreviousAssignedUserId != null)
                        RemoveMember(devicePreviousAssignedUserId, (database) => new string[] { devicePreviousAssignedUserId });

                    if (deviceCurrentAssignedUserId != null)
                        AddMember(deviceCurrentAssignedUserId, (database) => new string[] { deviceCurrentAssignedUserId });
                });
            }
        }