2018-10-08 12:09:48 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2019-08-01 11:27:28 +02:00
|
|
|
|
using BeWo.Data;
|
2018-10-08 12:09:48 +02:00
|
|
|
|
using BeWo.Data.Access;
|
|
|
|
|
|
using BeWo.Data.Entities;
|
|
|
|
|
|
using BeWo.Service.Core;
|
|
|
|
|
|
using BeWo.Service.DCEntityMapper;
|
|
|
|
|
|
using BeWo.Service.MessageContracts;
|
|
|
|
|
|
using BS.Shared;
|
|
|
|
|
|
using BS.Shared.Core;
|
|
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
using BS.Shared.DataContracts.Compact;
|
|
|
|
|
|
using BS.Shared.Extensions;
|
|
|
|
|
|
using BS.Shared.Services;
|
2019-08-01 11:27:28 +02:00
|
|
|
|
using Utils = BeWo.Service.Core.Utils;
|
|
|
|
|
|
|
2018-10-08 12:09:48 +02:00
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Service.Plugins
|
|
|
|
|
|
{
|
|
|
|
|
|
public class EmployeeService : AbstractIDSpecificDefaultClass<EmployeeService>
|
|
|
|
|
|
{
|
2022-04-06 11:49:20 +02:00
|
|
|
|
public virtual EmployeeDC LoadEmployee(long eOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
SettingsLogic.AddToUsersHistory<Employee>(eOid);
|
|
|
|
|
|
var dc = MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.LoadByID<Employee>(eOid));
|
|
|
|
|
|
|
|
|
|
|
|
return dc;
|
2018-10-08 12:09:48 +02:00
|
|
|
|
|
2022-04-06 11:49:20 +02:00
|
|
|
|
}
|
2018-10-08 12:09:48 +02:00
|
|
|
|
public virtual long InsertNewEmployee(EmployeeDC pEmployeeDC)
|
|
|
|
|
|
{
|
|
|
|
|
|
Employee lEmployee = MapperFactory.EmployeeDC_Employee.MapToNewEntity(pEmployeeDC);
|
|
|
|
|
|
DAOFactory.GenericDAO.Insert(lEmployee);
|
|
|
|
|
|
return lEmployee.Oid.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual List<CompactEmployeeDC> GetAllActiveEmployeesCompact()
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.CompactEmployeeDC_Employee.MapToNewDCs(DAOFactory.GenericDAO.GetAllActive<Employee>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual List<CompactEmployeeDC> GetAllActiveAndArchivedEmployeesCompact()
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.CompactEmployeeDC_Employee.MapToNewDCs(DAOFactory.GenericDAO.GetAllActiveAndArchived<Employee>());
|
|
|
|
|
|
}
|
2019-08-01 11:27:28 +02:00
|
|
|
|
|
|
|
|
|
|
public virtual List<CompactTeamDC> GetAllTeamsCompact()
|
|
|
|
|
|
{
|
2023-03-31 12:32:08 +02:00
|
|
|
|
if (Utils.UserHasRight(GetLoggedInUser(), UserRightType.TeamView_ViewAll))
|
2019-08-01 11:27:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.CompactTeamDC_Team.MapToNewDCs(DAOFactory.GenericDAO.GetAllActive<Team>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-31 12:32:08 +02:00
|
|
|
|
if (Utils.UserHasRight(GetLoggedInUser(), UserRightType.TeamView_ViewMyTeams))
|
2019-08-01 11:27:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
var teams = DAOFactory.SearchDAO.FindAllActiveTeamsOfEmployee(LoggedInUserOperationContextExt.Current.User.Employee.Oid.Value);
|
|
|
|
|
|
return MapperFactory.CompactTeamDC_Team.MapToNewDCs(teams);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new List<CompactTeamDC>();
|
|
|
|
|
|
}
|
2020-08-17 15:50:00 +02:00
|
|
|
|
|
|
|
|
|
|
//Für Main Navigation View
|
|
|
|
|
|
public virtual List<CompactEmployeeDC> GetAllCompactEmployees()
|
|
|
|
|
|
{
|
|
|
|
|
|
var employees = DAOFactory.GenericDAO.GetAll<Employee>();
|
2022-02-15 12:33:15 +01:00
|
|
|
|
|
|
|
|
|
|
var dcs = MapperFactory.CompactEmployeeDC_Employee.MapToNewDCs(employees);
|
|
|
|
|
|
var teams = GetAllTeamsCompact();
|
|
|
|
|
|
|
|
|
|
|
|
var teamDCs = new List<TeamDC>();
|
|
|
|
|
|
foreach (var ct in teams)
|
|
|
|
|
|
teamDCs.Add(MapperFactory.TeamDC_Team.MapToNewDC(DAOFactory.GenericDAO.GetByID<Team>(ct.TeamOid)));
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var dc in dcs)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var tDC in teamDCs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tDC.Member.Contains(dc))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dc.TeamOids == null)
|
|
|
|
|
|
dc.TeamOids = new List<long>();
|
|
|
|
|
|
|
|
|
|
|
|
if (!dc.TeamOids.Contains(tDC.TeamOid.Value))
|
|
|
|
|
|
dc.TeamOids.Add(tDC.TeamOid.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dc.TeamOids != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var oid in dc.TeamOids)
|
|
|
|
|
|
{
|
|
|
|
|
|
var team = teamDCs.FirstOrDefault(t => t.TeamOid == oid);
|
|
|
|
|
|
if (team != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dc.RelatedTeams == null)
|
|
|
|
|
|
dc.RelatedTeams = "Teams: " + team.Name + ", ";
|
|
|
|
|
|
else
|
|
|
|
|
|
dc.RelatedTeams += team.Name + ", ";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dc.RelatedTeams != null && dc.RelatedTeams.Length > 0)
|
|
|
|
|
|
dc.RelatedTeams = dc.RelatedTeams.Remove(dc.RelatedTeams.Length - 2, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-17 15:50:00 +02:00
|
|
|
|
|
2022-02-15 12:33:15 +01:00
|
|
|
|
|
|
|
|
|
|
return dcs;
|
2020-08-17 15:50:00 +02:00
|
|
|
|
}
|
2022-04-25 15:45:02 +02:00
|
|
|
|
|
|
|
|
|
|
public virtual List<CompactEmployeeDC> GetAllAuthorizedCompactEmployees()
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = GetLoggedInUser();
|
|
|
|
|
|
|
|
|
|
|
|
var employees = DAOFactory.GenericDAO.GetAllActive<Employee>();
|
|
|
|
|
|
|
|
|
|
|
|
//var dcs = MapperFactory.CompactEmployeeDC_Employee.MapToNewDCs(employees);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = new List<CompactEmployeeDC>();
|
|
|
|
|
|
|
|
|
|
|
|
bool darfAlleSehen = false;
|
|
|
|
|
|
bool darfAlleDesTeamsSehen = false;
|
|
|
|
|
|
bool darfAlleEigenenSehen = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.Employee_AllowViewOwnEmployees))
|
|
|
|
|
|
{
|
|
|
|
|
|
darfAlleEigenenSehen = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.EmployeeView_View))
|
|
|
|
|
|
{
|
|
|
|
|
|
darfAlleSehen = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.Employee_AllowViewOwnTeam))
|
|
|
|
|
|
{
|
|
|
|
|
|
darfAlleDesTeamsSehen = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<long> teamMemberOids = new List<long>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in user.Employee.LeadingTeams)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var member in item.MemberList)
|
|
|
|
|
|
{
|
|
|
|
|
|
teamMemberOids.Add(member.Oid.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var emp in employees)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (darfAlleSehen)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Add(MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(emp));
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (darfAlleDesTeamsSehen)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (emp.Oid == user.Employee.Oid || teamMemberOids.Contains(emp.Oid.Value))
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Add(MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(emp));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (darfAlleEigenenSehen)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (emp.Oid == user.Employee.Oid)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Add(MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(emp));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result.OrderBy(e => e.LastName).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationUser GetLoggedInUser()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2023-03-31 12:32:08 +02:00
|
|
|
|
if(LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
|
2022-04-25 15:45:02 +02:00
|
|
|
|
{
|
|
|
|
|
|
return LoggedInUserOperationContextExt.Current.User;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-31 12:32:08 +02:00
|
|
|
|
return SessionFacade.LoggedInUser;
|
2022-04-25 15:45:02 +02:00
|
|
|
|
}
|
2018-10-08 12:09:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|