91 lines
3.0 KiB
C#
91 lines
3.0 KiB
C#
namespace LaaProduction.Personalization
|
|
{
|
|
using LaaProduction.Personalization.Interfaces;
|
|
using LaaProduction.Personalization.Models;
|
|
using LaaProduction.Personalization.Repositories.Interfaces;
|
|
using LaaProductionDI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class EmployeesManager : IEmployeesManager
|
|
{
|
|
private readonly IEmployeesRepository employeesRepository;
|
|
private readonly IFunctionsRepository functionsRepository;
|
|
private readonly IRolesRepository rolesRepository;
|
|
|
|
public EmployeesManager()
|
|
{
|
|
this.employeesRepository = LaaServiceProvider.GetService<IEmployeesRepository>();
|
|
this.functionsRepository = LaaServiceProvider.GetService<IFunctionsRepository>();
|
|
this.rolesRepository = LaaServiceProvider.GetService<IRolesRepository>();
|
|
}
|
|
|
|
public object GetEmployee(short employeeId)
|
|
{
|
|
var employee = this.employeesRepository.Find(employeeId);
|
|
|
|
if (employee != null)
|
|
{
|
|
employee.Roles = this.rolesRepository.All(employeeId) ?? Array.Empty<string>();
|
|
employee.Functions = this.functionsRepository.EmployeeAll(employeeId) ?? Array.Empty<string>();
|
|
}
|
|
|
|
return employee ?? new object { };
|
|
}
|
|
|
|
public IEnumerable<object> GetEmployees()
|
|
=> this.employeesRepository.All()
|
|
?? Array.Empty<Employee>();
|
|
|
|
public IEnumerable<object> GetRoles()
|
|
=> this.rolesRepository
|
|
.All()
|
|
.GroupBy(x => x.Name)
|
|
.Select(x => new
|
|
{
|
|
Name = x.Key,
|
|
Employees = x.Select(e => e.EmployeeId)
|
|
});
|
|
|
|
public IEnumerable<string> GetRoles(short employeeId)
|
|
=> this.rolesRepository.All(employeeId) ?? Array.Empty<string>();
|
|
|
|
public IEnumerable<object> ListEmployees()
|
|
=> this.employeesRepository
|
|
.All()
|
|
.Select(x => new { x.EmployeeId, x.FullName });
|
|
|
|
public void UpdateEmployeeFunctions(short employeeId, IEnumerable<string> functions)
|
|
{
|
|
this.functionsRepository.Delete(employeeId);
|
|
|
|
if (functions != null && functions.Any())
|
|
{
|
|
this.functionsRepository.Insert(employeeId, functions);
|
|
}
|
|
}
|
|
|
|
public void UpdateEmployeeRoles(short employeeId, IEnumerable<string> roles)
|
|
{
|
|
this.rolesRepository.Delete(employeeId);
|
|
|
|
if (roles != null && roles.Any())
|
|
{
|
|
this.rolesRepository.Insert(employeeId, roles);
|
|
}
|
|
}
|
|
|
|
public void UpdateRoleEmployees(string role, IEnumerable<short> employees)
|
|
{
|
|
this.rolesRepository.Delete(role);
|
|
|
|
if (employees != null && employees.Any())
|
|
{
|
|
this.rolesRepository.Insert(role, employees);
|
|
}
|
|
}
|
|
}
|
|
}
|