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

54 lines
1.9 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 SeWo.Validation
{
public class CustomServiceRecordValidator : ServiceRecordValidator
{
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
{
if (newServiceRecord.SupportConcept == null && newServiceRecord.CostBearer == null)
{
newServiceRecord.CostBearer2SupportConceptOid = null;
}
var result = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
bool hasOutOfEditLimit = false;
foreach (var r in result)
{
if (r.ResultType == ServiceRecordValidationResult.OutOfEditLimit)
{
hasOutOfEditLimit = true;
}
}
if (!hasOutOfEditLimit && !newServiceRecord.CostBearer2SupportConceptOid.HasValue)
{
if (maxDaysEditServiceRecordsAllowed > 0)
{
var dt = new DateTime(newServiceRecord.Start.Value.Year, newServiceRecord.Start.Value.Month, 1);
dt = dt.AddMonths(1);
dt = dt.AddDays(maxDaysEditServiceRecordsAllowed);
if (DateTime.Now >= dt)
result.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.OutOfEditLimit
});
}
}
return result;
}
}
}