90 lines
3.0 KiB
C#
90 lines
3.0 KiB
C#
namespace LaaProduction.Personalization
|
|
{
|
|
using LaaProduction.Personalization.Interfaces;
|
|
using LaaProduction.Personalization.Models;
|
|
using LaaProduction.Personalization.Repositories.Interfaces;
|
|
|
|
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(IEmployeesRepository employeesRepository, IFunctionsRepository functionsRepository, IRolesRepository rolesRepository)
|
|
{
|
|
this.employeesRepository = employeesRepository;
|
|
this.functionsRepository = functionsRepository;
|
|
this.rolesRepository = rolesRepository;
|
|
}
|
|
|
|
public Object GetEmployee(Int16 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(Int16 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(Int16 employeeId, IEnumerable<String> functions)
|
|
{
|
|
this.functionsRepository.Delete(employeeId);
|
|
|
|
if (functions != null && functions.Any())
|
|
{
|
|
this.functionsRepository.Insert(employeeId, functions);
|
|
}
|
|
}
|
|
|
|
public void UpdateEmployeeRoles(Int16 employeeId, IEnumerable<String> roles)
|
|
{
|
|
this.rolesRepository.Delete(employeeId);
|
|
|
|
if (roles != null && roles.Any())
|
|
{
|
|
this.rolesRepository.Insert(employeeId, roles);
|
|
}
|
|
}
|
|
|
|
public void UpdateRoleEmployees(String role, IEnumerable<Int16> employees)
|
|
{
|
|
this.rolesRepository.Delete(role);
|
|
|
|
if (employees != null && employees.Any())
|
|
{
|
|
this.rolesRepository.Insert(role, employees);
|
|
}
|
|
}
|
|
}
|
|
}
|