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 long? OriginatorOid { get; set; } public bool ShowEmployeeColors { get; set; } public List ServiceRecordList { get; set; } #region Mitarbeiter public List PossibleEmployees { get; set; } public int EmployeePageLimit => 10; public int EmployeePageCount => (PossibleEmployees?.Count ?? 0) / EmployeePageLimit; public List SelectedEmployee2SchedulerAppointments { get; set; } public List SelectedEmployees { get; set; } public List SelectedEmployeeOids { get => AppointmentSessionModel.SelectedEmployeeOids; set => AppointmentSessionModel.SelectedEmployeeOids = value; } public List SelectedEmployee2AppointmentOids { get => AppointmentSessionModel.SelectedEmployees2AppointmentOids; set => AppointmentSessionModel.SelectedEmployees2AppointmentOids = value; } #endregion #region Klienten public List PossibleCustomers { get; set; } public int CustomerPageLimit => 10; public int CustomerPageCount => (PossibleCustomers?.Count ?? 0) / CustomerPageLimit; public List 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 SelectedCustomerOids { get => AppointmentSessionModel.SelectedCustomerOids; set => AppointmentSessionModel.SelectedCustomerOids = value; } #endregion #region Ressourcen public Dictionary> ResourceCategories2Resources { get; set; } public List PossibleResources { get; set; } public int ResourcePageLimit => 10; public int ResourcePageCount => (ResourceCategories2Resources?.Keys?.Count ?? 0) / ResourcePageLimit; public List 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 SelectedResourceOids { get => AppointmentSessionModel.SelectedResourceOids; set => AppointmentSessionModel.SelectedResourceOids = value; } #endregion public AppointmentModel() { SessionModel = new AppointmentSessionModel(); } public AppointmentModel(List possibleCustomers, List possibleResources, List possibleEmployees, UserDC user, List selectedCustomers, List selectedResources, List employee2Appointments) { LoggedInUser = user; SessionModel = new AppointmentSessionModel(); SelectedCustomers = selectedCustomers; SelectedCustomerOids = selectedCustomers.Select(customer => customer.CustomerOid).ToList(); SelectedEmployee2SchedulerAppointments = employee2Appointments; SelectedEmployee2AppointmentOids = employee2Appointments .Where(employee2Appointment => employee2Appointment.Employee2SchedulerAppointmentOid.HasValue) .Select(employee2Appointment => employee2Appointment.Employee2SchedulerAppointmentOid.Value).ToList(); SelectedEmployees = employee2Appointments.Select(employee2Appointment => employee2Appointment.Employee).ToList(); SelectedEmployeeOids = employee2Appointments.Select(employee2Appointment => employee2Appointment.Employee.EmployeeOid).ToList(); SelectedResources = selectedResources; SelectedResourceOids = selectedResources .Where(resource => resource.ResourceOid.HasValue) .Select(resource => resource.ResourceOid.Value).ToList(); PossibleCustomers = possibleCustomers; PossibleResources = possibleResources; PossibleEmployees = possibleEmployees; if(PossibleCustomers.Count == 0 && selectedCustomers.Count > 0) { PossibleCustomers = selectedCustomers; } if(PossibleResources.Count == 0 && selectedResources.Count > 0) { PossibleResources = selectedResources; } if(PossibleEmployees.Count == 0 && SelectedEmployees.Count > 0) { PossibleEmployees = SelectedEmployees; } ResourceCategories2Resources = new Dictionary>(); foreach(var resource in PossibleResources) { ResourceCategories2Resources.AddOrUpdateValueInDictionary(resource.ResourceCategory, resource); } } 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; OriginatorOid = appointment.Originator.EmployeeOid; } 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; OriginatorOid = source.OriginatorOid; } } }