EmployeeHandlers.cs
5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Company.Employee;
using Sungero.Core;
using Sungero.CoreEntities;
namespace Sungero.Company
{
partial class EmployeeJobTitlePropertyFilteringServerHandler<T>
{
public virtual IQueryable<T> JobTitleFiltering(IQueryable<T> query, Sungero.Domain.PropertyFilteringEventArgs e)
{
if (_obj.Department != null)
return query.Where(x => Equals(x.Department, _obj.Department) || x.Department == null);
return query;
}
}
partial class EmployeeUiFilteringServerHandler<T>
{
public override IQueryable<T> Filtering(IQueryable<T> query, Sungero.Domain.UiFilteringEventArgs e)
{
query = base.Filtering(query, e);
if (Functions.Module.IsRecipientRestrict())
{
var visibleRecipientIds = Functions.Module.GetVisibleRecipientIds(Constants.Module.EmployeeTypeGuid);
return query.Where(c => visibleRecipientIds.Contains(c.Id));
}
return query;
}
}
partial class EmployeeFilteringServerHandler<T>
{
public virtual IQueryable<Sungero.Company.IJobTitle> JobTitleFiltering(IQueryable<Sungero.Company.IJobTitle> query, Sungero.Domain.FilteringEventArgs e)
{
return query.Where(r => Equals(r.Status, Status.Active));
}
public virtual IQueryable<Sungero.Company.IDepartment> DepartmentFiltering(IQueryable<Sungero.Company.IDepartment> query, Sungero.Domain.FilteringEventArgs e)
{
return query.Where(r => Equals(r.Status, Status.Active));
}
public virtual IQueryable<Sungero.Company.IBusinessUnit> BusinessUnitFiltering(IQueryable<Sungero.Company.IBusinessUnit> query, Sungero.Domain.FilteringEventArgs e)
{
return query.Where(r => Equals(r.Status, Status.Active));
}
public override IQueryable<T> Filtering(IQueryable<T> query, Sungero.Domain.FilteringEventArgs e)
{
if (_filter == null)
return query;
if (_filter.Active || _filter.Closed)
query = query.Where(r => _filter.Active && r.Status == Status.Active ||
_filter.Closed && r.Status == Status.Closed);
if (_filter.JobTitle != null)
query = query.Where(r => Equals(r.JobTitle, _filter.JobTitle));
if (_filter.Department != null)
{
var employees = Departments.GetAllUsersInGroup(_filter.Department).ToList();
query = query.Where(r => employees.Contains(r));
}
if (_filter.BusinessUnit != null)
{
var employees = Company.BusinessUnits.GetAllUsersInGroup(_filter.BusinessUnit).ToList();
query = query.Where(r => employees.Contains(r));
}
return query;
}
}
partial class EmployeeCreatingFromServerHandler
{
public override void CreatingFrom(Sungero.Domain.CreatingFromEventArgs e)
{
e.Without(_info.Properties.NeedNotifyNewAssignments);
e.Without(_info.Properties.NeedNotifyExpiredAssignments);
}
}
partial class EmployeeServerHandlers
{
public override IDigestModel GetDigest(Sungero.Domain.GetDigestEventArgs e)
{
return Sungero.Company.Functions.Module.GetEmployeePopup(_obj);
}
public override void Saved(Sungero.Domain.SavedEventArgs e)
{
var oldDepartment = _obj.State.Properties.Department.OriginalValue;
var newDepartment = _obj.Department;
if (!Equals(oldDepartment, newDepartment))
{
newDepartment.RecipientLinks.AddNew().Member = _obj;
if (oldDepartment != null)
foreach (var department in oldDepartment.RecipientLinks.Where(r => r.Member.Equals(_obj)).ToList())
oldDepartment.RecipientLinks.Remove(department);
}
}
public override void Deleting(Sungero.Domain.DeletingEventArgs e)
{
var systemSubstitutions = Substitutions.GetAll().Where(s => s.IsSystem == true && (s.Substitute.Equals(_obj) || s.User.Equals(_obj))).ToList();
foreach (var substitution in systemSubstitutions)
Substitutions.Delete(substitution);
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
_obj.NeedNotifyNewAssignments = true;
_obj.NeedNotifyExpiredAssignments = true;
_obj.NeedNotifyAssignmentsSummary = true;
}
public override void BeforeDelete(Sungero.Domain.BeforeDeleteEventArgs e)
{
_obj.Department.RecipientLinks.Remove(_obj.Department.RecipientLinks.Where(d => d.Member == _obj).FirstOrDefault());
}
public override void BeforeSave(Sungero.Domain.BeforeSaveEventArgs e)
{
Functions.Employee.UpdateName(_obj, _obj.Person);
if (string.IsNullOrEmpty(_obj.Name))
_obj.Name = " ";
if (!Functions.Employee.IsValidEmail(_obj.Email))
e.AddWarning(_obj.Info.Properties.Email, Parties.Resources.WrongEmailFormat);
else if (!Docflow.PublicFunctions.Module.IsASCII(_obj.Email))
e.AddWarning(_obj.Info.Properties.Email, Docflow.Resources.ASCIIWarning);
var oldDepartment = _obj.State.Properties.Department.OriginalValue;
var newDepartment = _obj.Department;
if (!Equals(oldDepartment, newDepartment))
{
if (newDepartment != null)
{
var newDepartmentLockInfo = Locks.GetLockInfo(newDepartment);
if (newDepartmentLockInfo.IsLockedByOther)
e.AddError(Employees.Resources.DeparmentLockedByUserFormat(newDepartment.Name, newDepartmentLockInfo.OwnerName));
}
if (oldDepartment != null)
{
var oldDepartmentLockInfo = Locks.GetLockInfo(oldDepartment);
if (oldDepartmentLockInfo.IsLockedByOther)
e.AddError(Employees.Resources.DeparmentLockedByUserFormat(oldDepartment.Name, oldDepartmentLockInfo.OwnerName));
}
}
}
}
}