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> ViewModelChanged; private ISchedulerViewModel _ActiveAppointmentViewModel; private Dictionary> _AllCats2ResInDic; public ISchedulerViewModel ActiveAppointmentViewModel { get => _ActiveAppointmentViewModel; set { if(value != null) { _ActiveAppointmentViewModel = value; ViewModelChanged?.Invoke(this, new EventArgs(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 ConvertAbsenceTimesToAppointments(IEnumerable pAbsenceTimes, DateTime pIntervalEnd, List 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(); } } }