508 lines
14 KiB
C#
508 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using BeWo.ViewModel;
|
|
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Scheduler.ViewModel
|
|
{
|
|
public class SchedulerAppointmentVM : AbstractDCMapperVM<SchedulerAppointmentDC>, IBeWoAppointment
|
|
{
|
|
public static string PropertyName_Type = "Type";
|
|
public static string PropertyName_Start = "Start";
|
|
public static string PropertyName_End = "End";
|
|
public static string PropertyName_AllDay = "AllDay";
|
|
public static string PropertyName_Subject = "Subject";
|
|
public static string PropertyName_Location = "Location";
|
|
public static string PropertyName_Status = "Status";
|
|
public static string PropertyName_RecurrenceInfo = "RecurrenceInfo";
|
|
public static string PropertyName_Description = "Description";
|
|
public static string PropertyName_EmployeeList = "EmployeeList";
|
|
public static string PropertyName_CustomerList = "CustomerList";
|
|
public static string PropertyName_ResourceList = "ResourceList";
|
|
public static string PropertyName_IsPrivate = "IsPrivate";
|
|
public static string PropertyName_Originator = "Originator";
|
|
public static string PropertyName_IsAbsenceTime = "IsAbsenceTime";
|
|
|
|
private bool _allDay;
|
|
private string _description;
|
|
private DateTime _end;
|
|
private string _location;
|
|
private string _recurrenceInfo;
|
|
private DateTime _start;
|
|
private int _status;
|
|
private string _subject;
|
|
private int _type;
|
|
private Dictionary<string, object> _customFields;
|
|
private bool _isPrivate;
|
|
private List<Employee2SchedulerAppointmentDC> _employeeList;
|
|
private List<CompactCustomerDC> _customerList;
|
|
private List<ResourceDC> _resourceList;
|
|
private CompactEmployeeDC _originator;
|
|
|
|
public object Id { get; set; }
|
|
public int LabelId { get; set; }
|
|
public Dictionary<string, object> CustomFields
|
|
{
|
|
get => _customFields ?? (_customFields = new Dictionary<string, object>());
|
|
set
|
|
{
|
|
if (!AreDifferent(_customFields, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_customFields = value;
|
|
|
|
EmployeeList = (List<Employee2SchedulerAppointmentDC>) value["EmployeeList"];
|
|
CustomerList = (List<CompactCustomerDC>) value["CustomerList"];
|
|
ResourceList = (List<ResourceDC>) value["ResourceList"];
|
|
Originator = (CompactEmployeeDC) value["Originator"];
|
|
IsPrivate = (bool) value["IsPrivate"];
|
|
}
|
|
}
|
|
|
|
public int EventType
|
|
{
|
|
get => _type;
|
|
set
|
|
{
|
|
if (AreDifferent(_type, value))
|
|
{
|
|
_type = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.Type, value), PropertyName_Type);
|
|
FirePropertyChanged(PropertyName_Type);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime End
|
|
{
|
|
get => _end;
|
|
set
|
|
{
|
|
if (AreDifferent(_end, value))
|
|
{
|
|
_end = value;
|
|
|
|
if (IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.EndDate, value), PropertyName_End);
|
|
FirePropertyChanged(PropertyName_End);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime Start
|
|
{
|
|
get => _start;
|
|
set
|
|
{
|
|
if (AreDifferent(_start, value))
|
|
{
|
|
_start = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.StartDate, value), PropertyName_Start);
|
|
FirePropertyChanged(PropertyName_Start);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool AllDay
|
|
{
|
|
get => _allDay;
|
|
set
|
|
{
|
|
if (AreDifferent(_allDay, value))
|
|
{
|
|
_allDay = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.AllDay, value), PropertyName_AllDay);
|
|
FirePropertyChanged(PropertyName_AllDay);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Subject
|
|
{
|
|
get => _subject;
|
|
set
|
|
{
|
|
if(AreDifferent(_subject, value))
|
|
{
|
|
_subject = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Subject, value), PropertyName_Subject);
|
|
FirePropertyChanged(PropertyName_Subject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Location
|
|
{
|
|
get => _location;
|
|
set
|
|
{
|
|
if (AreDifferent(_location, value))
|
|
{
|
|
_location = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Location, value), PropertyName_Location);
|
|
FirePropertyChanged(PropertyName_Location);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Status
|
|
{
|
|
get => _status;
|
|
set
|
|
{
|
|
if (AreDifferent(_status, value))
|
|
{
|
|
_status = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Status, value), PropertyName_Status);
|
|
FirePropertyChanged(PropertyName_Status);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsTeilnahmeBestaetigung { get; }
|
|
|
|
public string RecurrenceInfo
|
|
{
|
|
get => _recurrenceInfo;
|
|
set
|
|
{
|
|
if (AreDifferent(_recurrenceInfo, value))
|
|
{
|
|
_recurrenceInfo = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.RecurrenceInfo, value), PropertyName_RecurrenceInfo);
|
|
FirePropertyChanged(PropertyName_RecurrenceInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Description
|
|
{
|
|
get => _description;
|
|
set
|
|
{
|
|
if (AreDifferent(_description, value))
|
|
{
|
|
_description = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Description, value), PropertyName_Description);
|
|
FirePropertyChanged(PropertyName_Description);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<Employee2SchedulerAppointmentDC> EmployeeList
|
|
{
|
|
get => _employeeList ?? (_employeeList = new List<Employee2SchedulerAppointmentDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_employeeList, value))
|
|
{
|
|
_employeeList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.EmployeeList, value), PropertyName_EmployeeList);
|
|
FirePropertyChanged(PropertyName_EmployeeList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<CompactCustomerDC> CustomerList
|
|
{
|
|
get => _customerList ?? (_customerList = new List<CompactCustomerDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_customerList, value))
|
|
{
|
|
_customerList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.CustomerList, value), PropertyName_CustomerList);
|
|
FirePropertyChanged(PropertyName_CustomerList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<ResourceDC> ResourceList
|
|
{
|
|
get => _resourceList ?? (ResourceList = new List<ResourceDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_resourceList, value))
|
|
{
|
|
_resourceList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.ResourceList, value), PropertyName_ResourceList);
|
|
FirePropertyChanged(PropertyName_ResourceList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsPrivate
|
|
{
|
|
get => _isPrivate;
|
|
set
|
|
{
|
|
if (AreDifferent(_isPrivate, value))
|
|
{
|
|
_isPrivate = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.IsPrivate,value), PropertyName_IsPrivate);
|
|
FirePropertyChanged(PropertyName_IsPrivate);
|
|
}
|
|
}
|
|
}
|
|
|
|
public CompactEmployeeDC Originator
|
|
{
|
|
get => _originator;
|
|
set
|
|
{
|
|
if (AreDifferent(_originator, value))
|
|
{
|
|
_originator = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Originator, value), PropertyName_Originator);
|
|
FirePropertyChanged(PropertyName_Originator);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual TimeSpan EndTime => End.TimeOfDay;
|
|
|
|
public virtual TimeSpan StartTime => Start.TimeOfDay;
|
|
|
|
public virtual bool IsAbsenceTime { get; }
|
|
|
|
public SchedulerAppointmentVM(SchedulerAppointmentDC pDC) : base(pDC, pDC.SchedulerAppointmentOid == null)
|
|
{
|
|
IsTeilnahmeBestaetigung = pDC.IsTeilnahmeBestaetigung;
|
|
}
|
|
|
|
public SchedulerAppointmentVM(bool pAllDay, string pSubject, DateTime pStart, DateTime pEnd, CompactEmployeeDC pOriginator)
|
|
{
|
|
_allDay = pAllDay;
|
|
_subject = pSubject;
|
|
_start = pStart;
|
|
_end = pEnd;
|
|
_originator = pOriginator;
|
|
|
|
IsAbsenceTime = true;
|
|
|
|
UpdateCustomFields();
|
|
}
|
|
|
|
public void UpdateCustomFields()
|
|
{
|
|
CustomFields = new Dictionary<string, object>
|
|
{
|
|
{PropertyName_EmployeeList, EmployeeList},
|
|
{PropertyName_CustomerList, CustomerList},
|
|
{PropertyName_ResourceList, ResourceList},
|
|
{PropertyName_Originator, Originator},
|
|
{PropertyName_IsPrivate, IsPrivate},
|
|
{PropertyName_IsAbsenceTime, IsAbsenceTime}
|
|
};
|
|
}
|
|
|
|
protected override void InitByDataContract(SchedulerAppointmentDC pDataContract)
|
|
{
|
|
_allDay = pDataContract.AllDay;
|
|
_description = pDataContract.Description;
|
|
_end = pDataContract.EndDate ?? DateTime.Now;
|
|
_location = pDataContract.Location;
|
|
_recurrenceInfo = pDataContract.RecurrenceInfo;
|
|
_start = pDataContract.StartDate ?? DateTime.Now;
|
|
_status = pDataContract.Status;
|
|
_subject = pDataContract.Subject;
|
|
_type = pDataContract.Type;
|
|
_isPrivate = pDataContract.IsPrivate;
|
|
_originator = pDataContract.Originator;
|
|
_customerList = pDataContract.CustomerList;
|
|
_employeeList = pDataContract.EmployeeList;
|
|
_resourceList = pDataContract.ResourceList;
|
|
}
|
|
|
|
protected override SchedulerAppointmentDC MapToDataContract(SchedulerAppointmentDC pDataContract, bool doCommit)
|
|
{
|
|
pDataContract.AllDay = _allDay;
|
|
pDataContract.Description = _description;
|
|
pDataContract.EndDate = _end;
|
|
pDataContract.Location = _location;
|
|
pDataContract.RecurrenceInfo = _recurrenceInfo;
|
|
pDataContract.StartDate = _start;
|
|
pDataContract.Status = _status;
|
|
pDataContract.Subject = _subject;
|
|
pDataContract.Type = _type;
|
|
pDataContract.IsPrivate = _isPrivate;
|
|
pDataContract.Originator = _originator;
|
|
pDataContract.CustomerList = _customerList;
|
|
pDataContract.EmployeeList = _employeeList;
|
|
pDataContract.ResourceList = _resourceList;
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override bool Equals(object pObj)
|
|
{
|
|
if (!(pObj is SchedulerAppointmentVM))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var obj = (SchedulerAppointmentVM) pObj;
|
|
|
|
var customFieldsAreEqual = false;
|
|
|
|
if(CustomFields.Count == obj.CustomFields.Count)
|
|
{
|
|
for (var i = 0; i < CustomFields.Count; i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
var employeeList1 = (List<Employee2SchedulerAppointmentDC>) CustomFields.ElementAt(i).Value;
|
|
var objEmployeeList1 = (List<Employee2SchedulerAppointmentDC>) obj.CustomFields.ElementAt(i).Value;
|
|
|
|
customFieldsAreEqual = employeeList1 == null && objEmployeeList1 == null || employeeList1 != null && employeeList1.AreEqual(objEmployeeList1);
|
|
break;
|
|
case 1:
|
|
var customerList1 = (List<CompactCustomerDC>) CustomFields.ElementAt(i).Value;
|
|
var objCustomerList1 = (List<CompactCustomerDC>) obj.CustomFields.ElementAt(i).Value;
|
|
|
|
customFieldsAreEqual = customerList1 == null && objCustomerList1 == null || customerList1 != null && customerList1.AreEqual(objCustomerList1);
|
|
break;
|
|
case 2:
|
|
var resourceList1 = (List<ResourceDC>) CustomFields.ElementAt(i).Value;
|
|
var objResourceList1 = (List<ResourceDC>) obj.CustomFields.ElementAt(i).Value;
|
|
|
|
customFieldsAreEqual = resourceList1 == null && objResourceList1 == null || resourceList1 != null && resourceList1.AreEqual(objResourceList1);
|
|
break;
|
|
case 3:
|
|
var originator1 = (CompactEmployeeDC) CustomFields.ElementAt(i).Value;
|
|
var objOriginator1 = (CompactEmployeeDC) CustomFields.ElementAt(i).Value;
|
|
|
|
customFieldsAreEqual = originator1 == null && objOriginator1 == null || originator1 != null && originator1.Equals(objOriginator1);
|
|
break;
|
|
case 4:
|
|
var isPrivate1 = Convert.ToBoolean(CustomFields.ElementAt(i).Value);
|
|
var objIsPrivate1 = Convert.ToBoolean(CustomFields.ElementAt(i).Value);
|
|
|
|
customFieldsAreEqual = isPrivate1 == objIsPrivate1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var areEqual =
|
|
LabelId == obj.LabelId &&
|
|
AllDay == obj.AllDay &&
|
|
IsPrivate == obj.IsPrivate &&
|
|
IsDirty == obj.IsDirty &&
|
|
IsNew == obj.IsNew &&
|
|
customFieldsAreEqual &&
|
|
CustomerList.AreEqual(obj.CustomerList) &&
|
|
Equals(Description, obj.Description) &&
|
|
EmployeeList.AreEqual(obj.EmployeeList) &&
|
|
Equals(End, obj.End) &&
|
|
Equals(EndTime, obj.EndTime) &&
|
|
Equals(Location, obj.Location) &&
|
|
ResourceList.AreEqual(obj.ResourceList) &&
|
|
Equals(RecurrenceInfo, obj.RecurrenceInfo);
|
|
|
|
return areEqual;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return DataContract.SchedulerAppointmentOid.HasValue
|
|
? GetType().Name.GetHashCode() ^ DataContract.SchedulerAppointmentOid.Value.GetHashCode()
|
|
: base.GetHashCode();
|
|
}
|
|
|
|
public override bool IsDirty => !IsAbsenceTime && base.IsDirty;
|
|
|
|
public new bool IsNew
|
|
{
|
|
get => !IsAbsenceTime && base.IsNew;
|
|
|
|
set => base.IsNew = value;
|
|
}
|
|
}
|
|
}
|