namespace LaaProduction.Personalization { using LaaProduction.Personalization.Interfaces; using LaaProduction.Personalization.Models; using LaaProduction.Personalization.Repositories.Interfaces; using System; using System.Collections.Generic; public class EmployeesManager : IEmployeesManager { private readonly IEmployeesRepository employeesRepository; private readonly IFunctionsRepository functionsRepository; private readonly IRolesRepository rolesRepository; public EmployeesManager() { this.employeesRepository = ServiceProvider.GetService(); this.functionsRepository = ServiceProvider.GetService(); this.rolesRepository = ServiceProvider.GetService(); } public object GetEmployee(short employeeId) { var employee = this.employeesRepository.Find(employeeId); if (employee != null) { employee.Roles = this.rolesRepository.All(employeeId) ?? Array.Empty(); employee.Functions = this.functionsRepository.EmployeeAll(employeeId) ?? Array.Empty(); } return employee ?? new object { }; } public IEnumerable GetEmployees() => this.employeesRepository.All() ?? Array.Empty(); public IEnumerable GetRoles() => this.rolesRepository.All() ?? Array.Empty(); public IEnumerable GetRoles(short employeeId) => this.rolesRepository.All(employeeId) ?? Array.Empty(); public void UpdateEmployeeFunctions(short employeeId, IEnumerable functions) { this.functionsRepository.Delete(employeeId); this.functionsRepository.Insert(employeeId, functions); } public void UpdateEmployeeRoles(short employeeId, IEnumerable roles) { this.rolesRepository.Delete(employeeId); this.rolesRepository.Insert(employeeId, roles); } } }