Files
BeWoPlaner/BeWo/SchulbegleitenderDienst/SBDUtils/SBDUtils.cs
2019-09-27 15:55:01 +02:00

72 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using BS.Shared;
using BS.Shared.Extensions;
namespace BeWo.SchulbegleitenderDienst.SBDUtils
{
public static class SBDUtils
{
public static SubstitutionListObject GetListType(List<TagesansichtVM> viewModels)
{
var unwantedSubstitutionList = new List<TagesansichtVM>();
var employeeSubstitutionList = new List<TagesansichtVM>();
var customerSubstitutionList = new List<TagesansichtVM>();
foreach (var viewModel in viewModels)
{
if(viewModel.VertretungsStatus != VertretungsStatus.KlientKrank)
{
var substitutionStartingDayCountCondition = false;
if (viewModel.Customer != null)
{
var substitutionNeededDate = DateTime.Now.AddDays(-1 * viewModel.Customer.SubstitutionStartingDayCount);
if (viewModel.Absencetime?.Start.HasValue ?? false)
{
substitutionStartingDayCountCondition = viewModel.Customer.SubstitutionNeed != SubstitutionNeed.NoSubstitutionWanted && substitutionNeededDate < viewModel.Absencetime.Start && viewModel.Customer.SubstitutionStartingDayCount > 0;
}
}
if (substitutionStartingDayCountCondition || viewModel.Vertretung?.VertretenderMitarbeiterOid != null || viewModel.Customer != null && viewModel.Customer.SubstitutionNeed == SubstitutionNeed.NoSubstitutionWanted)
{
unwantedSubstitutionList.AddIfNotIn(viewModel);
}
else
{
employeeSubstitutionList.AddIfNotIn(viewModel);
}
}
else
{
if(viewModel.Customer.SubstitutionNeed == SubstitutionNeed.SubstitutionNeeded || viewModel.Customer.SubstitutionNeed == SubstitutionNeed.SubstitutionWanted)
{
customerSubstitutionList.Add(viewModel);
}
else
{
unwantedSubstitutionList.Add(viewModel);
}
}
}
return new SubstitutionListObject(employeeSubstitutionList, customerSubstitutionList, unwantedSubstitutionList);
}
}
public struct SubstitutionListObject
{
public List<TagesansichtVM> AbsentEmployeesList { get; set; }
public List<TagesansichtVM> AbsentCustomersList { get; set; }
public List<TagesansichtVM> SubstitutionUnwantedList { get; set; }
public SubstitutionListObject(List<TagesansichtVM> absentEmployees, List<TagesansichtVM> absentCustomers, List<TagesansichtVM> substitutionUnwanted)
{
AbsentEmployeesList = absentEmployees;
AbsentCustomersList = absentCustomers;
SubstitutionUnwantedList = substitutionUnwanted;
}
}
}