Files
BeWoPlaner/BeWo/SchulbegleitenderDienst/SBDUtils/SBDUtils.cs
Lyndon Jetten c5c1ba59c2 .
2019-12-19 14:27:03 +01:00

115 lines
5.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using BS.Shared;
using BS.Shared.Extensions;
namespace BeWo.SchulbegleitenderDienst.SBDUtils
{
public static class SBDUtils
{
// FÜr die Tagesansicht optimiert
public static DailySubstitutionListObject CreateSubstitutionListObject(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 = SubstitutionStartingDayCountCondition(viewModel);
if (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 DailySubstitutionListObject(employeeSubstitutionList, customerSubstitutionList, unwantedSubstitutionList);
}
private static bool SubstitutionStartingDayCountCondition(TagesansichtVM viewModel)
{
var substitutionStartingDayCountCondition = false;
if (viewModel?.Customer != null && viewModel.Absencetime?.Start != null)
{
var substitutionNeededStartDate = viewModel.Absencetime?.Start.Value.Date.AddDays(viewModel.Customer.SubstitutionStartingDayCount - 1);
substitutionStartingDayCountCondition = viewModel.Customer.SubstitutionNeed != SubstitutionNeed.NoSubstitutionWanted && viewModel.Datum < substitutionNeededStartDate;
}
return substitutionStartingDayCountCondition;
}
public static WeeklySubstitutionListObject CreateWeeklySubstitutionListObject(List<WochenansichtVM> viewModels)
{
var unwantedSubstitutionList = new List<WochenansichtVM>();
var employeeSubstitutionList = new List<WochenansichtVM>();
var customerSubstitutionList = new List<WochenansichtVM>();
foreach (var viewModel in viewModels)
{
var isCustomerAbsenceWeekView = viewModel.WeekDayDictionary.Where(w => w.Value != null).All(a => a.Value.VertretungsStatus == VertretungsStatus.KlientKrank);
var isSubstitutionUnwanted = viewModel.WeekDayDictionary.Where(w => w.Value != null).All(a => SubstitutionStartingDayCountCondition(a.Value) || a.Value.Vertretung?.VertretenderMitarbeiterOid != null || a.Value.Customer != null && a.Value.Customer.SubstitutionNeed == SubstitutionNeed.NoSubstitutionWanted);
if (isSubstitutionUnwanted)
{
unwantedSubstitutionList.AddIfNotIn(viewModel);
}
else if(isCustomerAbsenceWeekView)
{
customerSubstitutionList.AddIfNotIn(viewModel);
}
else
{
employeeSubstitutionList.AddIfNotIn(viewModel);
}
}
return new WeeklySubstitutionListObject(employeeSubstitutionList, customerSubstitutionList, customerSubstitutionList);
}
}
public struct DailySubstitutionListObject
{
public List<TagesansichtVM> AbsentEmployeesList { get; set; }
public List<TagesansichtVM> AbsentCustomersList { get; set; }
public List<TagesansichtVM> SubstitutionUnwantedList { get; set; }
public DailySubstitutionListObject(List<TagesansichtVM> absentEmployees, List<TagesansichtVM> absentCustomers, List<TagesansichtVM> substitutionUnwanted)
{
AbsentEmployeesList = absentEmployees;
AbsentCustomersList = absentCustomers;
SubstitutionUnwantedList = substitutionUnwanted;
}
}
public struct WeeklySubstitutionListObject
{
public List<WochenansichtVM> AbsentEmployeesList { get; set; }
public List<WochenansichtVM> AbsentCustomersList { get; set; }
public List<WochenansichtVM> SubstitutionUnwantedList { get; set; }
public WeeklySubstitutionListObject(List<WochenansichtVM> absentEmployees, List<WochenansichtVM> absentCustomers, List<WochenansichtVM> substitutionUnwanted)
{
AbsentEmployeesList = absentEmployees;
AbsentCustomersList = absentCustomers;
SubstitutionUnwantedList = substitutionUnwanted;
}
}
}