private void RefreshEmployees(List <IActorRef> requestors) { void RefreshingEmployees(object message) { switch (message) { case EmployeesQuery.Response queryResult: this.employees.Clear(); this.employees.AddRange(queryResult.Employees); this.Become(this.RefreshFinished(requestors)); break; case RefreshDepartmentInfo newInfo when newInfo.Department.DepartmentId == this.departmentInfo.DepartmentId: requestors.Add(this.Sender); break; default: this.Stash.Stash(); break; } } this.organizationEmployeesActor.Tell(EmployeesQuery.Create().ForDepartment(this.departmentInfo.DepartmentId)); this.Become(RefreshingEmployees); }
private async Task <EmployeeMetadata> GetEmployee(string employeeId) { var employeesResponse = await this.organizationActor.Ask <EmployeesQuery.Response>( EmployeesQuery.Create().WithId(employeeId)); return(employeesResponse.Employees.FirstOrDefault()?.Metadata); }
public async Task <IActionResult> FilterEmployees( [FromQuery] string departmentId, [FromQuery] string roomNumber, [FromQuery] string name, CancellationToken token) { var query = EmployeesQuery.Create(); if (!string.IsNullOrWhiteSpace(departmentId)) { query = query.ForDepartment(departmentId); } if (!string.IsNullOrWhiteSpace(roomNumber)) { query = query.ForRoom(roomNumber); } if (!string.IsNullOrWhiteSpace(name)) { query = query.WithNameFilter(name); } var employees = await this.LoadEmployeesAsync(query, token); return(this.Ok(employees)); }
private void RefreshHead(IActorRef requestor) { var requestors = new List <IActorRef>() { requestor }; void RefreshingHead(object message) { switch (message) { case EmployeesQuery.Response queryResult: this.head = queryResult.Employees.FirstOrDefault(); this.RefreshEmployees(requestors); break; case RefreshDepartmentInfo newInfo when newInfo.Department.DepartmentId == this.departmentInfo.DepartmentId: requestors.Add(this.Sender); break; default: this.Stash.Stash(); break; } } this.organizationEmployeesActor.Tell(EmployeesQuery.Create().WithId(this.departmentInfo.ChiefId)); this.Become(RefreshingHead); }
protected override EmployeesQuery GetEmployeesQuery(DateTime date) { return(EmployeesQuery.Create().WithHireDate(new DateQuery() { Day = date.Day, Month = date.Month })); }
private UntypedReceive GetUserEmployee() { void OnMessage(object message) { switch (message) { case ReceiveTimeout _: Log.Debug($"Cannot get permissions for '${this.userIdentity}' due to timeout"); this.ReplyAndStop(); break; case EmployeesQuery.Response userEmployee when userEmployee.Employees.Count == 0: Log.Debug($"Cannot find an employee for '{this.userIdentity}'"); this.ReplyAndStop(); break; case EmployeesQuery.Response userEmployee: this.defaultEmployeePermission = ExistingEmployeeDefaultPermission; BulkBumpPermissions(userEmployee.Employees.Select(x => x.Metadata.EmployeeId), SelfPermissions, this.permissionsForEmployees); //that can be fixed (as array, not First(), when DepartmentsQuery starts to //support arrays for Heads and DepartmentIds this.Become(this.GetOwnDepartments(userEmployee.Employees.First().Metadata)); break; default: this.Unhandled(message); break; } } this.organizationActor.Tell(EmployeesQuery.Create().WithIdentity(this.userIdentity)); return(OnMessage); }
GetAdditionalData(CalendarEventChanged message) { var ownerEmployeeTask = this.organizationActor.Ask <EmployeesQuery.Response>( EmployeesQuery.Create().WithId(message.NewEvent.EmployeeId)); var ownerPreferencesTask = this.userPreferencesActor.Ask <GetUserPreferencesMessage.Response>( new GetUserPreferencesMessage(message.NewEvent.EmployeeId)); await Task.WhenAll(ownerEmployeeTask, ownerPreferencesTask); return(ownerEmployeeTask.Result, ownerPreferencesTask.Result); }
public async Task <EmployeeContainer> FindOrDefaultAsync(ClaimsPrincipal user, CancellationToken cancellationToken) { if (!user.Identity.IsAuthenticated) { return(null); } var query = EmployeesQuery.Create().WithIdentity(user.Identity.Name); var employees = await this.employeesRegistry.SearchAsync(query, cancellationToken); return(employees.SingleOrDefault()); }
GetAdditionalData(CalendarEventAssignedToApprover message) { var ownerEmployeeTask = this.organizationActor.Ask <EmployeesQuery.Response>( EmployeesQuery.Create().WithId(message.Event.EmployeeId)); var approverPreferencesTask = this.userPreferencesActor.Ask <GetUserPreferencesMessage.Response>( new GetUserPreferencesMessage(message.ApproverId)); var approverPushTokensTask = this.pushDevicesActor.Ask <GetDevicePushTokensByEmployee.Success>( new GetDevicePushTokensByEmployee(message.ApproverId)); await Task.WhenAll(ownerEmployeeTask, approverPreferencesTask, approverPushTokensTask); return(ownerEmployeeTask.Result, approverPreferencesTask.Result, approverPushTokensTask.Result); }
GetAdditionalData(CalendarEventApprovalsChanged message) { var lastApproval = message.Approvals .OrderByDescending(a => a.Timestamp) .First(); var ownerPreferencesTask = this.userPreferencesActor.Ask <GetUserPreferencesMessage.Response>( new GetUserPreferencesMessage(message.Event.EmployeeId)); var ownerPushTokensTask = this.pushDevicesActor.Ask <GetDevicePushTokensByEmployee.Success>( new GetDevicePushTokensByEmployee(message.Event.EmployeeId)); var approverEmployeeTask = this.organizationActor.Ask <EmployeesQuery.Response>( EmployeesQuery.Create().WithId(lastApproval.ApprovedBy)); await Task.WhenAll(ownerPreferencesTask, ownerPushTokensTask, approverEmployeeTask); return(ownerPreferencesTask.Result, ownerPushTokensTask.Result, approverEmployeeTask.Result); }
private async Task <IEnumerable <object> > GetEmailNotifications( string employeeId, UserPreferences userPreferences, IEnumerable <CalendarEvent> vacations) { if (!userPreferences.EmailNotifications) { return(Enumerable.Empty <EmailNotification>()); } var employeeResponse = await this.organizationActor.Ask <EmployeesQuery.Response>( EmployeesQuery.Create().WithId(employeeId)); var employeeMetadata = employeeResponse.Employees.First().Metadata; return(vacations.Select(e => this.CreateEmailNotification(e, employeeMetadata))); }
protected override void OnReceive(object message) { switch (message) { case CalendarEventCreated msg when msg.Event.Type == CalendarEventTypes.Sickleave: this.organizationActor .Ask <EmployeesQuery.Response>(EmployeesQuery.Create().WithId(msg.Event.EmployeeId)) .ContinueWith(task => new CalendarEventChangedWithAdditionalData(msg.Event, NotificationType.Created, task.Result.Employees.FirstOrDefault()?.Metadata)) .PipeTo(this.Self); break; case CalendarEventChanged msg when msg.NewEvent.Type == CalendarEventTypes.Sickleave && msg.NewEvent.Status == SickLeaveStatuses.Requested && msg.OldEvent.Status == SickLeaveStatuses.Requested && msg.OldEvent.Dates.EndDate != msg.NewEvent.Dates.EndDate: this.organizationActor .Ask <EmployeesQuery.Response>(EmployeesQuery.Create().WithId(msg.NewEvent.EmployeeId)) .ContinueWith(task => new CalendarEventChangedWithAdditionalData(msg.NewEvent, NotificationType.Prolonged, task.Result.Employees.FirstOrDefault()?.Metadata)) .PipeTo(this.Self); break; case CalendarEventChanged msg when msg.NewEvent.Type == CalendarEventTypes.Sickleave && msg.NewEvent.Status == SickLeaveStatuses.Cancelled: this.organizationActor .Ask <EmployeesQuery.Response>(EmployeesQuery.Create().WithId(msg.NewEvent.EmployeeId)) .ContinueWith(task => new CalendarEventChangedWithAdditionalData(msg.NewEvent, NotificationType.Cancelled, task.Result.Employees.FirstOrDefault()?.Metadata)) .PipeTo(this.Self); break; case CalendarEventChanged _: break; case CalendarEventChangedWithAdditionalData msg: var notificationAction = msg.NotificationType == NotificationType.Created ? "created" : msg.NotificationType == NotificationType.Prolonged ? "prolonged" : "cancelled"; this.logger.Debug($"Sending a sick leave {notificationAction} accounting email notification for user {msg.Event.EmployeeId}"); var notificationConfiguration = msg.NotificationType == NotificationType.Created ? this.createdEmailNotificationConfig : msg.NotificationType == NotificationType.Prolonged ? this.prolongedEmailNotificationConfig : this.cancelledEmailNotificationConfig; this.SendNotification(msg, notificationConfiguration); break; default: this.Unhandled(message); break; } }