if (date.Training != null)
{
var training = date.Training;
var status = new TrainingStatus();
var refresher = new Training();
if (training.Trainings != null)
refresher = training.Trainings;
bool hasTakenRefresher = false;
status.Value = date.Date.AddDays(
TrainingHelper.CalculateValidityDays(training.Validity ?? 0, training.ValidityType ?? 0));
status.Name = training.TrainingName;
status.ID = training.TrainingID;
status.Category = training.CategoryTraining != null ? training.CategoryTraining.Name : "Other";
status.IsTrained = _validityUtilsService.IsValid(training, date.Date);
if (status.IsTrained)
{
status.IsExpiring = _validityUtilsService.IsExpiring(training, date.Date,
TrainingHelper.CalculateValidityDays(
training.ExpirationWarningValidity ?? 0,
training.ExpirationWarningValidityType ?? 0));
}
if (refresher.ID != 0)
{
hasTakenRefresher = employee.Dates
.Count(x => x.Training != null
&& x.TrainingID == refresher.ID) > 1;
if (hasTakenRefresher && (status.IsExpiring || !status.IsTrained))
{
status.IsExpiring = false;
var trainingWithNewValidity = new Training();
status.Value = date.Date.AddDays(
TrainingHelper.CalculateValidityDays(training.ValidityRefresher ?? 0,
training.ValidityRefresherType ?? 0));
trainingWithNewValidity.Validity = training.ValidityRefresher;
trainingWithNewValidity.ValidityType = training.ValidityRefresherType;
status.IsTrained = _validityUtilsService.IsValid(trainingWithNewValidity, date.Date);
if (status.IsTrained)
{
status.IsExpiring = _validityUtilsService.IsExpiring(trainingWithNewValidity, date.Date,
TrainingHelper.CalculateValidityDays(
refresher.ExpirationWarningValidity ?? 0,
refresher.ExpirationWarningValidityType ?? 0));
}
}
}
if (status.IsTrained && !status.IsExpiring)
status.Status = TrainingStatuses.Trained;
else if (status.IsTrained && status.IsExpiring)
status.Status = TrainingStatuses.Expiring;
else if (!status.IsTrained && !status.IsExpiring)
status.Status = TrainingStatuses.Expired;
status.EmpID = employee.ID;
return status;
}
test