Files
BeWoPlaner/BeWo/SchulbegleitenderDienst/SBDUtils/SBDUtils.cs
Lyndon Jetten dd96a5b0f7 Der Vertretungsalgorithmus wurde überarbeitet und berücksichtigt jetzt die Betreuungszeiten.
"Vertretung ab dem x. Tag" beginnt jetzt bei 1 und nicht mehr bei 0. Ein DB-Skript passt alle Werte mit 0 an -> Changes_2019_12_07 AbWelchemKrankheitsTag UPDATE.txt
2019-12-07 21:06:03 +01:00

89 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.ServiceProxy;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
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>();
var customer2AbsenceTimes = new Dictionary<CompactCustomerDC, List<AbsenceTimeDC>>();
viewModels.Where(w => w.VertretungsStatus == VertretungsStatus.KlientKrank && w.Customer != null).DoForEach(vi =>
{
customer2AbsenceTimes.AddOrUpdateValueInDictionary(vi.Customer, vi.Absencetime);
});
var employeeAbsenceTimes = viewModels.Where(w => w.VertretungsStatus != VertretungsStatus.KlientKrank && w.Customer != null).ToList();
var itemsForunwantedSubstitutionList = new List<TagesansichtVM>();
foreach (var item in employeeAbsenceTimes)
{
if (customer2AbsenceTimes.ContainsKey(item.Customer))
{
item.KlientStatusColor = "#7FFF7F";
itemsForunwantedSubstitutionList.AddIfNotIn(item);
}
}
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 - 1));
if (viewModel.Absencetime?.Start.HasValue ?? false)
{
substitutionStartingDayCountCondition = viewModel.Customer.SubstitutionNeed != SubstitutionNeed.NoSubstitutionWanted && substitutionNeededDate < viewModel.Absencetime.Start && viewModel.Customer.SubstitutionStartingDayCount > 0;
}
}
if (itemsForunwantedSubstitutionList.Contains(viewModel) || substitutionStartingDayCountCondition || viewModel.Vertretung?.VertretenderMitarbeiterOid != null || viewModel.Customer != null && viewModel.Customer.SubstitutionNeed == SubstitutionNeed.NoSubstitutionWanted)
{
unwantedSubstitutionList.AddIfNotIn(viewModel);
}
else
{
employeeSubstitutionList.AddIfNotIn(viewModel);
}
}
else
{
customerSubstitutionList.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;
}
}
}