Files
BeWoPlaner/ReportImp/DiakoniewerkEssen/Validation/ServiceRecordValidator.cs

61 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
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 DiakonieWerkEssen.Validation
{
public class BetreuwoServiceRecordValidator : ServiceRecordValidator
{
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
{
var result = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
bool hasZukunftResult = false;
foreach (var r in result)
{
if (r.ResultType == ServiceRecordValidationResult.Custom && r.Message.Contains("Zukunft"))
{
hasZukunftResult = true;
}
}
if (!hasZukunftResult)
{
if (newServiceRecord.Start.Value > DateTime.Now)
{
result.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Das gewählte Datum darf nicht in der Zukunft liegen."
});
}
}
// Dokumentationsfeld ist Pflicht - außer bei Arbeitszeiterfassung
if (!newServiceRecord.ServiceDescription.Category.Name.ToLower().Contains("arbeitszeiterfassung"))
{
if (newServiceRecord.Notice.IsNullOrEmpty())
{
result.Add(new ServiceRecordValidationResultDC
{
Allow = false,
EmployeeName = newServiceRecord.Employee.LastName + ", " + newServiceRecord.Employee.FirstName,
StartDate = newServiceRecord.Start.Value,
EndDate = newServiceRecord.End.Value,
ResultType = ServiceRecordValidationResult.Custom,
Message = "Das Dokumentationsfeld muss ausgefüllt werden."
});
}
}
return result;
}
}
}