77 lines
2.8 KiB
C#
77 lines
2.8 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;
|
|
|
|
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);
|
|
}
|
|
|
|
internal void InitNewTask(Appointment pAppointment, DateTime? pDueDate, IEnumerable<Employee2SchedulerAppointmentDC> pSelectedEmployees, List<CompactCustomerDC> pSelectedCustomers, List<ResourceDC> pSelectedResources, List<CompactSupportConceptDC> pSelectedSupportConcepts)
|
|
{
|
|
ActiveAppointmentViewModel?.InitNewTask(pAppointment, pDueDate, pSelectedEmployees, pSelectedCustomers, pSelectedResources, pSelectedSupportConcepts);
|
|
}
|
|
|
|
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.Where(w => w.AbsenceTimeOid.HasValue && w.Start.HasValue).Select(abwesenheit =>
|
|
{
|
|
var subject = $"{abwesenheit.Reason.Description}";
|
|
var employee = abwesenheit.EmployeeOid != null ? allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value) : null;
|
|
|
|
if(employee != null)
|
|
{
|
|
subject += $" ({employee.SimpleDescription})";
|
|
}
|
|
|
|
var absenceTimeEnd = abwesenheit.End?.AddTicks(1);
|
|
|
|
return new SchedulerAppointmentVM(true, subject, abwesenheit.Start.Value, abwesenheit.End ?? pIntervalEnd, employee, abwesenheit.Start, absenceTimeEnd);
|
|
}).ToList();
|
|
}
|
|
}
|
|
}
|