208 lines
7.8 KiB
C#
208 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.ClientPartials;
|
|
using BS.Shared.DataContracts.Compact;
|
|
|
|
namespace BS.Shared.Services
|
|
{
|
|
public class SupportConceptService
|
|
{
|
|
public static List<SupportConceptGoalDC> CreateGoalTree(List<ValueListEntryDC> allGoalsAndCategories, ObservableSortCollection<ValueListEntryDC> selectedGoals)
|
|
{
|
|
var goalList = new List<SupportConceptGoalDC>();
|
|
|
|
if(allGoalsAndCategories != null)
|
|
{
|
|
var ziele = allGoalsAndCategories.Where(w => w.Type.Equals(ValueListEntryType.SupportConceptGoalCategoryType) || w.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalCategoryType)).OrderBy(s => s.TypeDescription).ToList();
|
|
var massnahmen = allGoalsAndCategories.Where(w => w.Type.Equals(ValueListEntryType.SupportConceptGoalType) || w.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType)).OrderBy(s => s.TypeDescription).ToList();
|
|
var goalCategoryDict = new Dictionary<long, SupportConceptGoalDC>();
|
|
|
|
|
|
foreach(var goalCat in ziele)
|
|
{
|
|
var treeItem = new SupportConceptGoalDC
|
|
{
|
|
GoalEntryDC = goalCat,
|
|
IsExpanded = true
|
|
};
|
|
|
|
if(!goalCategoryDict.ContainsKey(goalCat.ValueListEntryOid.Value))
|
|
{
|
|
goalCategoryDict.Add(goalCat.ValueListEntryOid.Value, treeItem);
|
|
}
|
|
|
|
if(goalCat.ParentOid == null)
|
|
{
|
|
goalList.Add(treeItem);
|
|
}
|
|
}
|
|
|
|
foreach(var ziel in ziele.Where(w => w.ParentOid != null))
|
|
{
|
|
if(goalCategoryDict.ContainsKey(ziel.ParentOid.Value) && goalCategoryDict.ContainsKey(ziel.ValueListEntryOid.Value))
|
|
{
|
|
goalCategoryDict[ziel.ValueListEntryOid.Value].ParentGoal = goalCategoryDict[ziel.ParentOid.Value];
|
|
}
|
|
}
|
|
|
|
var zieleMitEltern = goalCategoryDict.Values.Where(w => w.GoalEntryDC.ParentOid != null).ToList();
|
|
foreach(var ziel in zieleMitEltern)
|
|
{
|
|
if(goalCategoryDict.ContainsKey(ziel.GoalEntryDC.ParentOid.Value))
|
|
{
|
|
goalCategoryDict[ziel.GoalEntryDC.ParentOid.Value].Children.Add(ziel);
|
|
}
|
|
}
|
|
|
|
var zieleOhneKinder = goalCategoryDict.Values.Where(w => w.Children.Count == 0).ToList();
|
|
foreach(var ziel in zieleOhneKinder)
|
|
{
|
|
CheckIfSelected(ziel, selectedGoals);
|
|
}
|
|
|
|
foreach(var goal in massnahmen)
|
|
{
|
|
var kind = new SupportConceptGoalDC { GoalEntryDC = goal };
|
|
|
|
CheckIfSelected(kind, selectedGoals);
|
|
|
|
if(goal.ParentOid != null && goalCategoryDict.ContainsKey(goal.ParentOid.Value))
|
|
{
|
|
var parentItem = goalCategoryDict[goal.ParentOid.Value];
|
|
kind.ParentGoal = parentItem;
|
|
|
|
parentItem.Children.Add(kind);
|
|
}
|
|
}
|
|
}
|
|
|
|
return goalList;
|
|
}
|
|
|
|
private static void CheckIfSelected(SupportConceptGoalDC goal, ICollection<ValueListEntryDC> selectedGoals)
|
|
{
|
|
if(selectedGoals != null)
|
|
{
|
|
foreach(var existingGoal in selectedGoals)
|
|
{
|
|
if(existingGoal.Equals(goal.GoalEntryDC))
|
|
{
|
|
goal.IsChecked = true;
|
|
}
|
|
}
|
|
|
|
goal.PropertyChanged += (s, e) =>
|
|
{
|
|
if(s is SupportConceptGoalDC selectedGoal)
|
|
{
|
|
if(selectedGoal.IsChecked)
|
|
{
|
|
selectedGoals.Add(selectedGoal.GoalEntryDC);
|
|
}
|
|
else
|
|
{
|
|
selectedGoals.Remove(selectedGoal.GoalEntryDC);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public static FlatSupportConceptTreeNodeDC CreateFlatSupportConceptItem(CompactSupportConceptDC dc, CompactOrganisationDC orga)
|
|
{
|
|
var flatNode = new FlatSupportConceptTreeNodeDC();
|
|
|
|
if(dc != null)
|
|
{
|
|
var treeNode = new SupportConceptTreeNodeDC
|
|
{
|
|
SupportConcept = dc,
|
|
Customer = dc.Customer
|
|
};
|
|
|
|
if(dc.CostBearerList.Count > 0)
|
|
{
|
|
CompactCostBearerDC cbDC = null;
|
|
|
|
if(orga != null)
|
|
{
|
|
foreach(var item in dc.CostBearerList)
|
|
{
|
|
if(orga.Equals(item.Organisation))
|
|
{
|
|
cbDC = item;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(cbDC == null)
|
|
{
|
|
cbDC = dc.CostBearerList[0];
|
|
}
|
|
|
|
var orgDC = new CompactOrganisationDC();
|
|
var relDC = new SupportConceptCostBearerRelDC();
|
|
|
|
orgDC.CostBearerID = cbDC.CostBearerID;
|
|
orgDC.CostBearerOid = cbDC.CostBearerOid;
|
|
|
|
var o = orga;
|
|
if(o == null && cbDC != null)
|
|
{
|
|
o = cbDC.Organisation;
|
|
}
|
|
|
|
if(o != null)
|
|
{
|
|
orgDC.OrganisationOid = o.OrganisationOid;
|
|
orgDC.Name = o.Name;
|
|
orgDC.ActualHourlyRate = o.ActualHourlyRate;
|
|
orgDC.ActualMinuteIntervall = o.ActualMinuteIntervall;
|
|
orgDC.ActualRateFactor = o.ActualRateFactor;
|
|
orgDC.CostRatePeriods = o.CostRatePeriods;
|
|
orgDC.IsCalculatingWithFactor = o.IsCalculatingWithFactor;
|
|
}
|
|
|
|
relDC.ApprovedEndDate = cbDC.ApprovedEndDate;
|
|
relDC.ApprovedStartDate = cbDC.ApprovedStartDate;
|
|
relDC.CostBearer = orgDC;
|
|
relDC.CostBearer2SupportConceptOid = cbDC.CostBearer2SupportConceptOid;
|
|
relDC.RequestedEndDate = cbDC.RequestedEndDate;
|
|
relDC.RequestedStartDate = cbDC.RequestedStartDate;
|
|
relDC.Status = cbDC.SupportConceptStatus;
|
|
relDC.SupportConcept = dc;
|
|
relDC.AuswahlBezeichnung = cbDC.Bezeichnung;
|
|
|
|
treeNode.SupportConceptCostBearerRelDC = relDC;
|
|
treeNode.CostBearer = orgDC;
|
|
}
|
|
|
|
flatNode.SupportConceptTreeNodeDC = treeNode;
|
|
}
|
|
|
|
return flatNode;
|
|
}
|
|
|
|
public static CompactSupportConceptDC HoleHilfeplanAusListe(List<CompactSupportConceptDC> scList, CompactCustomerDC customerCompact, DateTime firstTime, DateTime lastTime)
|
|
{
|
|
foreach(var sc in scList)
|
|
{
|
|
if(sc.Customer.Oid == customerCompact.Oid)
|
|
{
|
|
if(sc.StartDate.HasValue && sc.EndDate.HasValue && sc.StartDate <= lastTime &&
|
|
sc.EndDate >= firstTime)
|
|
{
|
|
return sc;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|