private void RecreateEmployeeAgents(IReadOnlyCollection <EmployeeStoredInformation> allEmployees)
        {
            var removedIds = this.EmployeesById.Keys.Except(allEmployees.Select(x => x.Metadata.EmployeeId)).ToList();


            foreach (var removedId in removedIds)
            {
                var actorToRemove = this.EmployeesById[removedId];
                actorToRemove.Tell(PoisonPill.Instance);
                Context.Unwatch(actorToRemove);
                this.EmployeesById.Remove(removedId);
            }

            var newEmployeesCount = 0;

            foreach (var employeeNewInfo in allEmployees)
            {
                if (this.EmployeesById.TryGetValue(employeeNewInfo.Metadata.EmployeeId, out var employee))
                {
                    employee.Tell(new EmployeeActor.UpdateEmployeeInformation(employeeNewInfo));
                }
                else
                {
                    employee = Context.ActorOf(
                        EmployeeActor.GetProps(employeeNewInfo, this.imageResizer, this.vacationsRegistry),
                        $"employee-{Uri.EscapeDataString(employeeNewInfo.Metadata.EmployeeId)}");

                    this.EmployeesById[employeeNewInfo.Metadata.EmployeeId] = employee;
                    Context.Watch(employee);
                    newEmployeesCount++;
                }
            }

            this.logger.Debug($"Employees list is updated. There are {allEmployees.Count} at all, {removedIds.Count} got removed, {newEmployeesCount} were added");
        }
        private void RecreateEmployeeAgents(IReadOnlyCollection <EmployeeStoredInformation> allEmployees)
        {
            this.logger.Debug("Recreating employee agents...");
            var removedIds = this.employeesById.Keys.Except(allEmployees.Select(x => x.Metadata.EmployeeId)).ToList();

            foreach (var removedId in removedIds)
            {
                this.employeesById.Remove(removedId);
            }

            var persistenceSupervisorFactory = new PersistenceSupervisorFactory();

            var newEmployeesCount = 0;

            foreach (var employeeNewInfo in allEmployees)
            {
                IActorRef employeeActor;
                var       employeeId = employeeNewInfo.Metadata.EmployeeId;

                if (this.employeesById.TryGetValue(employeeId, out var employee))
                {
                    employeeActor = employee.EmployeeActor;
                    employeeActor.Tell(new EmployeeActor.UpdateEmployeeInformation(employeeNewInfo));
                }
                else
                {
                    var employeeActorProps = EmployeeActor.GetProps(
                        employeeNewInfo,
                        this.imageResizer,
                        this.vacationsCreditRegistry,
                        this.employeeVacationsRegistryPropsFactory,
                        this.employeeSickLeavesRegistryPropsFactory);
                    employeeActor = Context.ActorOf(
                        persistenceSupervisorFactory.Get(employeeActorProps),
                        $"employee-{Uri.EscapeDataString(employeeId)}");

                    newEmployeesCount++;
                }

                this.employeesById[employeeId] = new EmployeeIndexEntry(employeeActor, employeeNewInfo.Metadata);
            }

            this.logger.Debug($"Employees list is updated. There are {allEmployees.Count} at all, {removedIds.Count} got removed, {newEmployeesCount} were added");
        }
        private void RecreateEmployeeAgents(IReadOnlyCollection <EmployeeInfo> allEmployees)
        {
            var removedIds     = this.EmployeesById.Keys.Except(allEmployees.Select(x => x.EmployeeId)).ToImmutableList();
            var addedEmployees = allEmployees.Where(x => !this.EmployeesById.ContainsKey(x.EmployeeId)).ToImmutableList();

            foreach (var removedId in removedIds)
            {
                this.EmployeesById[removedId].Tell(PoisonPill.Instance);
                this.EmployeesById.Remove(removedId);
            }

            foreach (var addedEmployee in addedEmployees)
            {
                var employee = Context.ActorOf(EmployeeActor.Props(addedEmployee), Uri.EscapeDataString(addedEmployee.EmployeeId));
                this.EmployeesById[addedEmployee.EmployeeId] = employee;
            }

            this.logger.Debug($"Employees list is updated. There are {allEmployees.Count} at all, {removedIds.Count} got removed, {addedEmployees.Count} were added");
        }