Files
BeWoPlaner/BeWoPlanerMobil/Models/AppointmentModel.cs
2026-05-08 11:05:48 +02:00

213 lines
7.8 KiB
C#

using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
namespace BeWoPlanerMobil.Models
{
[Serializable]
public class AppointmentModel : AbstractModel
{
public AppointmentSessionModel AppointmentSessionModel => SessionModel as AppointmentSessionModel;
public long? Oid { get; set; }
public int? EventType { get; set; }
public int? Label { get; set; }
public bool AllDay { get; set; }
public string Location { get; set; }
public int? Status { get; set; }
public string RecurrenceInfo { get; set; }
public string Subject { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public string Description { get; set; }
public bool IsPrivate { get; set; }
public bool CanBeEdited { get; set; }
public bool IsTask { get; set; }
public DateTime? DueDate { get; set; }
public DateTime? CompletedDate { get; set; }
public string CompletedNotice { get; set; }
public string CompletedUser { get; set; }
public string TaskDescription { get; set; }
public bool HasServiceRecordEntry { get; set; }
public List<ServiceRecordDC> ServiceRecordList { get; set; }
#region Mitarbeiter
public List<CompactEmployeeDC> PossibleEmployees { get; set; }
public int EmployeePageLimit => 10;
public int EmployeePageCount => (PossibleEmployees?.Count ?? 0) / EmployeePageLimit;
public List<Employee2SchedulerAppointmentDC> SelectedEmployee2SchedulerAppointments { get; set; }
public List<CompactEmployeeDC> SelectedEmployees { get; set; }
public List<long> SelectedEmployeeOids
{
get => AppointmentSessionModel.SelectedEmployeeOids;
set => AppointmentSessionModel.SelectedEmployeeOids = value;
}
public List<long> SelectedEmployees2Appointments
{
get => AppointmentSessionModel.SelectedEmployees2Appointments;
set => AppointmentSessionModel.SelectedEmployees2Appointments = value;
}
#endregion
#region Klienten
public List<CompactCustomerDC> PossibleCustomers { get; set; }
public int CustomerPageLimit => 10;
public int CustomerPageCount => (PossibleCustomers?.Count ?? 0) / CustomerPageLimit;
public List<CompactCustomerDC> SelectedCustomers
{
get
{
return SelectedCustomerOids is null ? null : PossibleCustomers.Where(customer => SelectedCustomerOids.Contains(customer.CustomerOid)).ToList();
}
set
{
SelectedCustomerOids = value?.Select(customer => customer.CustomerOid).ToList();
}
}
public List<long> SelectedCustomerOids
{
get => AppointmentSessionModel.SelectedCustomerOids;
set => AppointmentSessionModel.SelectedCustomerOids = value;
}
#endregion
#region Ressourcen
public Dictionary<ValueListEntryDC, List<ResourceDC>> ResourceCategories2Resources { get; set; }
public List<ResourceDC> PossibleResources { get; set; }
public int ResourcePageLimit => 10;
public int ResourcePageCount => (ResourceCategories2Resources?.Keys?.Count ?? 0) / ResourcePageLimit;
public List<ResourceDC> SelectedResources
{
get
{
return SelectedResourceOids is null ?
null :
PossibleResources.Where(resource => resource.ResourceOid.HasValue && SelectedResourceOids.Contains(resource.ResourceOid.Value)).ToList();
}
set
{
SelectedResourceOids = value?.Where(resource => resource.ResourceOid.HasValue).Select(resource => resource.ResourceOid.Value).ToList();
}
}
public List<long> SelectedResourceOids
{
get => AppointmentSessionModel.SelectedResourceOids;
set => AppointmentSessionModel.SelectedResourceOids = value;
}
#endregion
public AppointmentModel()
{
SessionModel = new AppointmentSessionModel();
}
public AppointmentModel(List<CompactCustomerDC> possibleCustomers, List<ResourceDC> possibleResources, List<CompactEmployeeDC> possibleEmployees)
{
PossibleCustomers = possibleCustomers;
PossibleResources = possibleResources;
PossibleEmployees = possibleEmployees;
ResourceCategories2Resources = new Dictionary<ValueListEntryDC, List<ResourceDC>>();
foreach(var resource in PossibleResources)
{
ResourceCategories2Resources.AddOrUpdateValueInDictionary(resource.ResourceCategory, resource);
}
SessionModel = new AppointmentSessionModel();
}
public AppointmentModel(SchedulerAppointmentDC appointment)
{
if(appointment is null)
{
return;
}
SessionModel = new AppointmentSessionModel();
Oid = appointment.SchedulerAppointmentOid;
EventType = appointment.Type;
AllDay = appointment.AllDay;
Location = appointment.Location;
Status = appointment.Status;
RecurrenceInfo = appointment.RecurrenceInfo;
Subject = appointment.Subject;
StartTime = appointment.StartDate;
EndTime = appointment.EndDate;
Description = appointment.Description;
SelectedCustomers = appointment.CustomerList;
SelectedEmployees = appointment.EmployeeList?.Select(employee2Appointment => employee2Appointment.Employee)?.ToList();
SelectedEmployee2SchedulerAppointments = appointment.EmployeeList;
SelectedResources = appointment.ResourceList;
HasServiceRecordEntry = appointment.HasServiceRecordEntry;
ServiceRecordList = appointment.ServiceRecordList;
CanBeEdited = appointment.CanBeEdited;
IsPrivate = appointment.IsPrivate;
IsTask = appointment.IsTask;
DueDate = appointment.DueDate;
CompletedDate = appointment.CompletedDate;
CompletedNotice = appointment.CompletedNotice;
CompletedUser = appointment.CompletedUser;
TaskDescription = appointment.TaskDescription;
}
public virtual void Assign(AppointmentModel source)
{
if(source is null)
{
return;
}
Oid = source.Oid;
EventType = source.EventType;
Label = source.Label;
AllDay = source.AllDay;
Location = source.Location;
Status = source.Status;
RecurrenceInfo = source.RecurrenceInfo;
Subject = source.Subject;
StartTime = source.StartTime;
EndTime = source.EndTime;
Description = source.Description;
SelectedCustomers = source.SelectedCustomers;
SelectedEmployees = source.SelectedEmployees;
SelectedEmployee2SchedulerAppointments = source.SelectedEmployee2SchedulerAppointments;
SelectedResources = source.SelectedResources;
HasServiceRecordEntry = source.HasServiceRecordEntry;
ServiceRecordList = source.ServiceRecordList;
CanBeEdited = source.CanBeEdited;
IsPrivate = source.IsPrivate;
IsTask = source.IsTask;
DueDate = source.DueDate;
CompletedDate = source.CompletedDate;
CompletedNotice = source.CompletedNotice;
CompletedUser = source.CompletedUser;
TaskDescription = source.TaskDescription;
}
}
}