115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace AlphaEv.Validation
|
|
{
|
|
public class CustomServiceRecordValidator : ServiceRecordValidator
|
|
{
|
|
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
|
|
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
|
|
{
|
|
var list = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
|
|
|
|
if (newServiceRecord.ServiceDescription.Category.IsBillable && newServiceRecord.RoundedDuration == 0)
|
|
{
|
|
|
|
list.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Die Dauer muss größer als 0 sein."
|
|
});
|
|
|
|
}
|
|
|
|
var sd = newServiceRecord.ServiceDescription.Name.ToLower();
|
|
var cat = newServiceRecord.ServiceDescription.Category.Name.ToLower();
|
|
|
|
if (cat.Contains("arztbesuch") ||
|
|
cat.Contains("krank") ||
|
|
cat.Contains("fortbildung") ||
|
|
cat.Contains("urlaub") ||
|
|
cat.Contains("indirekte zeiten") ||
|
|
(cat.Contains("betrieb") && cat.Contains("zeiten")))
|
|
{
|
|
if (sd.Contains("abwesend"))
|
|
{
|
|
if (!IAmNotTeamLeiter())
|
|
{
|
|
list.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Dieser Eintrag kann nur von Fachleitungen oder Bereichsleitungen angelegt werden."
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
bool hasZukunftResult = false;
|
|
|
|
foreach (var r in list)
|
|
{
|
|
if (r.ResultType == ServiceRecordValidationResult.Custom && r.Message.Contains("Zukunft"))
|
|
{
|
|
hasZukunftResult = true;
|
|
}
|
|
}
|
|
if (!hasZukunftResult)
|
|
{
|
|
if (newServiceRecord.End.Value > DateTime.Now)
|
|
{
|
|
list.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Das gewählte Datum darf nicht in der Zukunft liegen."
|
|
});
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private bool IAmNotTeamLeiter()
|
|
{
|
|
ApplicationUser loggedInUser;
|
|
|
|
if (LoggedInUserOperationContextExt.Current != null &&
|
|
LoggedInUserOperationContextExt.Current.User != null)
|
|
{
|
|
loggedInUser = LoggedInUserOperationContextExt.Current.User;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
loggedInUser = SessionFacade.LoggedInUser;
|
|
}
|
|
|
|
if (loggedInUser != null)
|
|
{
|
|
foreach (var group in loggedInUser.UserGroups)
|
|
{
|
|
if (group.Name == "Fachleitungen")
|
|
{
|
|
return true;
|
|
}
|
|
if (group.Name == "Bereichsleitungen")
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |