Files
BeWoPlaner/BeWo/Scheduler/ViewModel/NewSchedulerViewModel.cs

71 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Scheduler.View;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using DevExpress.XtraScheduler;
namespace BeWo.Scheduler.ViewModel
{
public class NewSchedulerViewModel
{
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
private ISchedulerViewModel _ActiveAppointmentViewModel;
private Dictionary<ValueListEntryDC, List<ResourceDC>> _AllCats2ResInDic;
public ISchedulerViewModel ActiveAppointmentViewModel
{
get => _ActiveAppointmentViewModel;
set
{
if(value != null)
{
_ActiveAppointmentViewModel = value;
ViewModelChanged?.Invoke(this, new EventArgs<ISchedulerViewModel>(value));
}
}
}
public AbstractAppointmentEditForm GetEditAppointmentForm(DevExpress.Xpf.Scheduler.SchedulerControl control, Appointment appointment)
{
return ActiveAppointmentViewModel?.GetEditAppointmentForm(control, appointment);
}
internal void InitNewAppointment(Appointment appointment)
{
ActiveAppointmentViewModel?.InitNewAppointment(appointment);
}
public SchedulerSettings SchedulerSettings { get; set; }
public SchedulerSettings GetActiveSettings()
{
return ActiveAppointmentViewModel == null ? null : SchedulerSettings ?? ActiveAppointmentViewModel.GetDefaultSchedulerSettings();
}
public IEnumerable<SchedulerAppointmentVM> ConvertAbsenceTimesToAppointments(IEnumerable<AbsenceTimeDC> pAbsenceTimes, DateTime pIntervalEnd, List<CompactEmployeeDC> allEmployees)
{
return pAbsenceTimes.Select(abwesenheit =>
{
var subject = $"{abwesenheit.Reason.Description}";
var employee = allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value);
if(employee != null)
{
subject += $" ({employee.SimpleDescription})";
}
return new SchedulerAppointmentVM(true, subject, abwesenheit.Start.Value, abwesenheit.End ?? pIntervalEnd, employee);
}).ToList();
}
}
}