2019-07-25 14:58:13 +02:00
using System ;
using System.Collections.Generic ;
2020-04-02 13:19:14 +02:00
using System.Globalization ;
2019-07-25 14:58:13 +02:00
using System.Linq ;
2025-06-11 22:56:25 +02:00
using System.Security.Cryptography ;
using System.Text ;
2019-07-25 14:58:13 +02:00
using System.Web.Mvc ;
using BeWoPlanerMobil.Models ;
using BeWoPlanerMobil.Service ;
2020-09-21 11:57:10 +02:00
using BeWoPlanerMobil.Util ;
2021-01-14 16:30:28 +01:00
using BS.Shared ;
2019-07-25 14:58:13 +02:00
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
using DevExpress.XtraScheduler ;
using DevExpress.XtraScheduler.Compatibility ;
2020-06-29 19:24:24 +02:00
using Newtonsoft.Json ;
2019-07-25 14:58:13 +02:00
using static BeWoPlanerMobil . Util . MobileUtils ;
2021-11-08 20:24:26 +01:00
using RecurrenceInformation = BS . Shared . Core . RecurrenceInformation ;
2019-07-25 14:58:13 +02:00
namespace BeWoPlanerMobil.Controllers
{
public class SchedulerController : AbstractBaseController
{
private SchedulerModel _Model ;
public SchedulerModel Model
{
get
{
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2019-07-25 14:58:13 +02:00
return null ;
}
2025-06-11 22:56:25 +02:00
if ( _Model = = null )
2019-07-25 14:58:13 +02:00
{
2025-06-11 22:56:25 +02:00
_Model = new SchedulerModel ( ) ;
InitModel ( _Model ) ;
InitViewModel ( ) ;
2019-07-25 14:58:13 +02:00
}
2025-06-11 22:56:25 +02:00
//if (((SchedulerModel) Session[ModelSessionConstants.SchedulerModelKey])?.LoggedInEmployee is null)
//{
// _Model = new SchedulerModel();
// InitModel(_Model);
// Session[ModelSessionConstants.SchedulerModelKey] = _Model;
//}
//else
//{
// _Model = (SchedulerModel) Session[ModelSessionConstants.SchedulerModelKey];
//}
2019-07-25 14:58:13 +02:00
return _Model ;
}
}
2025-06-11 22:56:25 +02:00
private void InitViewModel ( )
2019-07-25 14:58:13 +02:00
{
2025-06-11 22:56:25 +02:00
if ( Model . HasRightToInsertRessourceAppointments | | Model . HasRightToViewAllResourceAppointments )
2020-06-29 19:24:24 +02:00
{
2023-07-31 15:29:16 +02:00
var allResources = KalenderService . GetAllResources ( ) . OrderBy ( r = > r . Name ) . ToList ( ) ;
2020-06-29 19:24:24 +02:00
var categories2Resources = new Dictionary < ValueListEntryDC , List < ResourceDC > > ( ) ;
2025-06-11 22:56:25 +02:00
foreach ( var category in allResources . Select ( resource = > resource . ResourceCategory ) )
2020-06-29 19:24:24 +02:00
{
2023-07-31 15:29:16 +02:00
categories2Resources . AddOrUpdateValueInDictionary ( category , allResources . Where ( resource = > resource . ResourceCategory . Equals ( category ) ) . OrderBy ( r = > r . Name ) . ToList ( ) ) ;
2020-06-29 19:24:24 +02:00
}
2023-07-31 15:29:16 +02:00
Model . ResourceCategories2Resources = categories2Resources . OrderBy ( kvp = > kvp . Key . DisplayName ) . ToDictionary ( kvp = > kvp . Key , kvp = > kvp . Value ) ;
2020-06-29 19:24:24 +02:00
}
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee ? . EmployeeOid . HasValue ? ? false )
2022-12-30 16:28:23 +01:00
{
2025-06-11 22:56:25 +02:00
var compactEmployee = EmployeeService . GetActiveCompactEmployeeWithOid ( Model . LoggedInEmployee . EmployeeOid . Value ) ;
2022-12-30 16:28:23 +01:00
2023-07-31 15:29:16 +02:00
Model . MyTeamEmployees = EmployeeService . GetAllTeamMember ( compactEmployee ) . OrderBy ( employee = > employee . LastName ) . ToList ( ) ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
else if ( ! ( Model is null ) )
2022-12-30 16:28:23 +01:00
{
Model . MyTeamEmployees = new List < CompactEmployeeDC > ( ) ;
}
2025-06-11 22:56:25 +02:00
if ( Model . HasRightToViewTeams & & ( Model ? . LoggedInEmployee ? . EmployeeOid . HasValue ? ? false ) )
2022-12-30 16:28:23 +01:00
{
2025-06-11 22:56:25 +02:00
Model . MyTeams = EmployeeService . GetAllActiveCompactTeamsForEmployee ( Model . LoggedInEmployee . EmployeeOid . Value ) . OrderBy ( team = > team . Name ) . ToList ( ) ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
if ( ! ( Model is null ) )
2023-04-24 19:22:09 +02:00
{
2025-06-11 22:56:25 +02:00
Model . TeamMemberCustomerOids = EmployeeService . LoadTeamsRelatedCustomerOids ( LoggedInUser . Employee . EmployeeOid ) ;
}
if ( Model . HasRightToViewCustomerSelectionInScheduler )
{
Model . AllCustomers = CustomerService . GetAllActiveCompactCustomers ( ) . OrderBy ( customer = > customer . LastName ) . ToList ( ) ;
}
if ( Model . HasRightToViewEmployeeAppointments )
{
Model . AllEmployees = EmployeeService . GetAllActiveEmployeesCompact ( ) . OrderBy ( employee = > employee . LastName ) . ToList ( ) ;
}
//LoadAppointmentsForDate();
if ( Model . SelectedAppointmentOid . HasValue )
{
if ( Model . Appointments = = null )
{
LoadAppointmentsForDate ( ) ;
}
Model . SelectedAppointment = Model . Appointments . FirstOrDefault ( app = > app . SchedulerAppointmentOid . HasValue & & app . SchedulerAppointmentOid . Value = = Model . SelectedAppointmentOid . Value ) ;
}
SetHasResourcesEmployeesOrCustomers ( ) ;
UpdateSelectedObjects ( ) ;
}
private void UpdateSelectedObjects ( )
{
//mache aus dem Ressourcenkategorien Dictionary eine flache Liste:
var list = new List < ResourceDC > ( ) ;
Model . ResourceCategories2Resources . Values . DoForEach ( l = > l . DoForEach ( s = > list . AddIfNotIn ( s ) ) ) ;
Model . SelectedEmployees = Model . AllEmployees . Where ( employee = > Model . SelectedEmployeeOids . Contains ( employee . EmployeeOid ) ) . ToList ( ) ;
Model . SelectedCustomers = Model . AllCustomers . Where ( customer = > Model . SelectedCustomerOids . Contains ( customer . CustomerOid ) ) . ToList ( ) ;
Model . SelectedResources = list . Where ( resource = > resource . ResourceOid . HasValue & & Model . SelectedResourceOids . Contains ( resource . ResourceOid . Value ) ) . ToList ( ) ;
Model . SelectedEmployeesForFiltering = Model . AllEmployees . Where ( employee = > Model . SelectedEmployeeOidsForFiltering . Contains ( employee . EmployeeOid ) ) . ToList ( ) ;
Model . SelectedCustomersForFiltering = Model . AllCustomers . Where ( customer = > Model . SelectedCustomerOidsForFiltering . Contains ( customer . CustomerOid ) ) . ToList ( ) ;
Model . SelectedResourcesForFiltering = list . Where ( resource = > resource . ResourceOid . HasValue & & Model . SelectedResourceOidsForFiltering . Contains ( resource . ResourceOid . Value ) ) . ToList ( ) ;
Model . SelectedEmployeesForIntervalFinder = Model . AllEmployees . Where ( employee = > Model . SelectedEmployeeOidsForIntervalFinder . Contains ( employee . EmployeeOid ) ) . ToList ( ) ;
Model . SelectedCustomersForIntervalFinder = Model . AllCustomers . Where ( customer = > Model . SelectedCustomerOidsForIntervalFinder . Contains ( customer . CustomerOid ) ) . ToList ( ) ;
Model . SelectedResourcesForIntervalFinder = list . Where ( resource = > resource . ResourceOid . HasValue & & Model . SelectedResourceOidsForIntervalFinder . Contains ( resource . ResourceOid . Value ) ) . ToList ( ) ;
}
// ToDo: Überarbeiten? Es kam das Ansehen hinzu
private void SetHasResourcesEmployeesOrCustomers ( )
{
var isOwnAppointment = ! Model . IsInEditMode | | Model . SelectedAppointment ? . Originator . EmployeeOid = = LoggedInEmployee . EmployeeOid ;
var v1 = Model . HasRightToInsertEmployeeAppointments | | Model . IsInEditMode & & Model . HasRightToEditEmployeeAppointments ;
var v2 = Model . HasRightToInsertRessourceAppointments | | Model . IsInEditMode & & Model . HasRightToEditResourceAppointments ;
if ( Model . IsInEditMode & & ! isOwnAppointment )
{
v2 = Model . HasRightToEditOthersResourceAppointments ;
}
var v3 = Model . HasRightToInsertCustomerAppointments | | Model . IsInEditMode & & Model . HasRightToEditCustomerAppointments ;
Model . HasResourcesEmployeesOrCustomers = v1 | | v2 | | v3 ;
}
[Authorize]
public ActionResult Scheduler ( )
{
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) | | ! Model . IsAllowedToSeeScheduler )
{
return Logout ( ) ;
2023-04-24 19:22:09 +02:00
}
2020-04-02 13:19:14 +02:00
2019-07-25 14:58:13 +02:00
return View ( Model ) ;
}
2020-04-02 13:19:14 +02:00
private void LoadAppointmentsForDate ( )
2019-07-25 14:58:13 +02:00
{
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee . EmployeeOid is null )
2019-07-25 14:58:13 +02:00
{
2020-04-02 13:19:14 +02:00
return ;
}
2019-07-25 14:58:13 +02:00
2020-04-02 13:19:14 +02:00
var date = Model . SelectedDate ;
2021-11-08 20:24:26 +01:00
var monday = date . GetInSameCalendarWeek ( DayOfWeek . Monday ) ;
var sunday = monday . Date . AddDays ( 6 ) ;
var start = date ;
var end = date . AddDays ( 1 ) ;
if ( Model . SelectedSchedulerView = = "5" )
{
start = monday ;
end = monday . AddDays ( 4 ) ;
}
else if ( Model . SelectedSchedulerView = = "7" )
{
start = monday ;
end = sunday ;
}
2019-07-25 14:58:13 +02:00
2025-06-11 22:56:25 +02:00
var selectedCustomers = Model . SelectedCustomerOidsForFiltering ;
var selectedEmployees = Model . SelectedEmployeeOidsForFiltering . Clone ( ) ; //Wird soinst im KalenderService geändert
var selectedResources = Model . SelectedResourceOidsForFiltering ;
2019-07-29 19:40:14 +02:00
2025-06-11 22:56:25 +02:00
var appointments = KalenderService . LoadFilteredAppointmentsMitAufgaben ( Model . HasRightToViewEmployeeAppointments , Model . LoggedInEmployee . EmployeeOid . Value , start . Date , end , selectedEmployees , selectedCustomers , selectedResources , false , false , false , false , true , true ) . ToList ( ) ;
2020-04-24 19:08:09 +02:00
2024-11-13 19:54:49 +01:00
// Private Termine
2024-11-12 18:37:23 +01:00
foreach ( var appointment in appointments . Where ( a = > a . IsPrivate ) )
{
2025-06-11 22:56:25 +02:00
if ( appointment . Originator . Equals ( LoggedInUser . Employee ) | | appointment . EmployeeList . Any ( e2a = > e2a . Employee . Equals ( LoggedInUser . Employee ) ) )
2024-11-12 18:37:23 +01:00
{
continue ;
}
appointment . CanBeEdited = false ;
appointment . Description = "Privater Termin" ;
appointment . Subject = $"Privat ({appointment.Originator})" ;
}
2024-11-13 19:54:49 +01:00
// Unerledigte Aufgaben
2022-12-30 16:28:23 +01:00
var tasks = appointments . Where ( w = > w . IsTask & & w . CompletedDate is null ) . ToList ( ) ;
2020-04-24 19:08:09 +02:00
2020-04-02 13:19:14 +02:00
// Nur eigene Kliententermine ansehen
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToViewCustomerAppointments )
2020-04-02 13:19:14 +02:00
{
2025-06-11 22:56:25 +02:00
appointments = appointments . Where ( a = > a . CustomerList . All ( c = > LoggedInEmployee . RelatedCustomers . Any ( rc = > rc . Customer . Equals ( c ) ) ) ) . ToList ( ) ;
2020-04-02 13:19:14 +02:00
}
2019-07-29 19:40:14 +02:00
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToViewAllResourceAppointments )
2020-04-02 13:19:14 +02:00
{
appointments = appointments . Where ( a = > a . ResourceList . Count = = 0 ) . ToList ( ) ;
}
2019-07-29 19:40:14 +02:00
2025-06-11 22:56:25 +02:00
if ( ! Model . IsAllowedToSeeCustomers )
2020-04-02 13:19:14 +02:00
{
appointments = appointments . Where ( a = > a . CustomerList . Count = = 0 ) . ToList ( ) ;
}
2019-07-29 19:40:14 +02:00
2023-03-29 19:25:21 +02:00
// Wenn es ein ganztägiger Termin ist, eine Sekunde abziehen und beim Speichern wieder draufaddieren?
foreach ( var app in appointments . Where ( a = > a . AllDay ) )
{
2024-11-12 18:37:23 +01:00
if ( app . EndDate is null )
{
continue ;
}
2023-03-29 19:25:21 +02:00
app . EndDate = app . EndDate . Value . AddMinutes ( - 1 ) ;
}
2020-04-02 13:19:14 +02:00
var holySweetFlyingFuck = appointments . Where ( w = >
2021-11-08 20:24:26 +01:00
w . IsTask = = false & & // Aufgaben ausschließen
w . StartDate . HasValue & & w . EndDate . HasValue & & // Datumsangaben haben einen Wert
( date . InBetween ( w . StartDate . Value , w . EndDate . Value , false ) | | date . CompareShortDates ( w . StartDate . Value ) )
2023-01-16 14:33:52 +01:00
// Einzeltermine oder Ausnahmen und gelöschte Ausnahmen
2022-08-10 14:13:29 +02:00
& & ( w . RecurrenceInfo is null | | w . RecurrenceInfo ! = null & & ( w . Type = = 3 | | w . Type = = 4 ) )
2021-11-08 20:24:26 +01:00
) . ToList ( ) ;
2019-07-25 14:58:13 +02:00
2020-07-13 16:25:43 +02:00
var deletedOccurrences = holySweetFlyingFuck . Where ( w = > w . Type = = 4 ) . Select ( s = > BS . Shared . Core . Utils . GetOccurrenceId ( s . RecurrenceInfo ) ) . ToList ( ) ;
var changedOccurrences = holySweetFlyingFuck . Where ( w = > w . Type = = 3 ) . Select ( s = > BS . Shared . Core . Utils . GetOccurrenceId ( s . RecurrenceInfo ) ) . ToList ( ) ;
2019-07-25 14:58:13 +02:00
2020-04-02 13:19:14 +02:00
holySweetFlyingFuck = holySweetFlyingFuck . Where ( w = > w . Type ! = 4 ) . ToList ( ) ;
2021-11-08 20:24:26 +01:00
holySweetFlyingFuck . AddRangeIfElementsNotIn ( CalculateRecurrences ( appointments , start , end , changedOccurrences , deletedOccurrences ) ) ;
2022-12-30 16:28:23 +01:00
holySweetFlyingFuck . AddRange ( tasks ) ;
2021-11-08 20:24:26 +01:00
2024-11-13 19:54:49 +01:00
Model . Appointments = Model . ShouldLoadTasks ?
holySweetFlyingFuck . OrderByDescending ( appointment = > appointment . IsTask ) . ThenBy ( appointment = > appointment . StartDate ) . ToList ( ) :
holySweetFlyingFuck . Where ( w = > w . IsTask is false ) . OrderBy ( appointment = > appointment . StartDate ) . ToList ( ) ;
2021-11-08 20:24:26 +01:00
2025-06-11 22:56:25 +02:00
UpdateAppointmentListItems ( ) ;
2021-11-08 20:24:26 +01:00
2025-06-11 22:56:25 +02:00
Model . WeekViewObject = new WeekViewObject ( Model . Appointments , Model . SelectedDate . GetInSameCalendarWeek ( DayOfWeek . Monday ) , Model . LoggedInEmployee ) ;
}
private void UpdateAppointmentListItems ( )
{
var md5 = new MD5CryptoServiceProvider ( ) ;
2021-11-08 20:24:26 +01:00
2025-06-11 22:56:25 +02:00
var list = new List < AppointmentListItem > ( ) ;
foreach ( var appointment in Model . Appointments )
2021-11-08 20:24:26 +01:00
{
2025-06-11 22:56:25 +02:00
String key = String . Format ( "{0}_{1}" , appointment . SchedulerAppointmentOid , appointment . RecurrenceInfo ) ;
String id = BitConverter . ToString ( md5 . ComputeHash ( Encoding . UTF8 . GetBytes ( key ) ) ) . Replace ( "-" , "" ) . ToLower ( ) ;
var listItem = new AppointmentListItem ( id , appointment ) ;
list . Add ( listItem ) ;
2021-11-08 20:24:26 +01:00
}
2025-06-11 22:56:25 +02:00
Model . AppointmentListItems = list ;
2021-11-08 20:24:26 +01:00
}
private static IEnumerable < SchedulerAppointmentDC > CalculateRecurrences ( IEnumerable < SchedulerAppointmentDC > appointments , DateTime start , DateTime end , IReadOnlyCollection < RecurrenceInformation > changedOccurrences , IReadOnlyCollection < RecurrenceInformation > deletedOccurrences )
{
var result = new List < SchedulerAppointmentDC > ( ) ;
var interval = new TimeInterval ( start , end ) ;
foreach ( var appointment in appointments . Where ( app = > app . RecurrenceInfo ! = null & & app . Type = = 1 ) )
2020-04-02 13:19:14 +02:00
{
2020-07-13 16:25:43 +02:00
var recurrenceInfo = new RecurrenceInfo ( ) ;
recurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
var occurrenceCalculator = OccurrenceCalculator . CreateInstance ( recurrenceInfo ) ;
2019-07-25 14:58:13 +02:00
2020-07-13 16:25:43 +02:00
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
pattern . RecurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
pattern . Start = pattern . RecurrenceInfo . Start ;
pattern . End = pattern . RecurrenceInfo . End ;
var patternId = pattern . RecurrenceInfo . Id . ToString ( ) ;
2019-07-25 14:58:13 +02:00
2020-07-13 16:25:43 +02:00
var occurrences = occurrenceCalculator . CalcOccurrences ( interval , pattern ) ;
2019-07-25 14:58:13 +02:00
2020-07-13 16:25:43 +02:00
if ( occurrences . Count > 0 )
{
2021-11-08 20:24:26 +01:00
foreach ( var app in occurrences . GetAppointments ( interval ) )
2020-04-02 13:19:14 +02:00
{
2021-11-08 20:24:26 +01:00
var index = app . RecurrenceIndex ;
2023-03-03 21:54:36 +01:00
2020-07-13 16:25:43 +02:00
var duration = ( appointment . EndDate . Value - appointment . StartDate . Value ) . TotalMinutes ;
2021-11-08 20:24:26 +01:00
var isOutOfInterval = app . Start . GetShortDateTime ( ) . AreInBetweenDates ( app . Start . AddMinutes ( duration ) , start , end ) = = false ;
var isChangedOccurrence = changedOccurrences . Any ( a = > a . PatternId . Equals ( patternId ) & & a . Index = = index ) ;
var isDeletedOccurrence = deletedOccurrences . Any ( a = > a . PatternId . Equals ( patternId ) & & a . Index = = index ) ;
if ( isOutOfInterval | | isChangedOccurrence | | isDeletedOccurrence )
2019-07-25 14:58:13 +02:00
{
2020-07-13 16:25:43 +02:00
continue ;
2019-07-25 14:58:13 +02:00
}
2020-07-13 16:25:43 +02:00
var recurringAppointment = new SchedulerAppointmentDC
{
2022-05-12 18:36:05 +02:00
AllDay = appointment . AllDay ,
CustomerList = appointment . CustomerList ,
2023-03-14 16:12:52 +01:00
Description = appointment . Description ? . RemoveUppercaseEsszett ( ) ,
2022-05-12 18:36:05 +02:00
EmployeeList = appointment . EmployeeList ,
EndDate = app . Start . AddMinutes ( duration ) ,
2020-07-13 16:25:43 +02:00
FormerBookingSequenceOid = appointment . FormerBookingSequenceOid ,
2022-05-12 18:36:05 +02:00
IsPrivate = appointment . IsPrivate ,
2022-06-13 15:38:43 +02:00
LabelKey = appointment . LabelKey ,
2023-03-14 16:12:52 +01:00
Location = appointment . Location ? . RemoveUppercaseEsszett ( ) ,
2022-05-12 18:36:05 +02:00
Originator = appointment . Originator ,
RecurrenceInfo = app . RecurrenceInfo . ToXml ( ) ,
2023-03-03 21:54:36 +01:00
RecurrenceIndex = index ,
2022-05-12 18:36:05 +02:00
ReminderInfo = appointment . ReminderInfo ,
ResourceList = appointment . ResourceList ,
StartDate = app . Start ,
2023-03-14 16:12:52 +01:00
Subject = appointment . Subject ? . RemoveUppercaseEsszett ( ) ? ? "" ,
2023-03-03 21:54:36 +01:00
Type = ( int ) app . Type ,
ServiceRecordList = appointment . ServiceRecordList ,
SupportConceptList = appointment . SupportConceptList
2020-07-13 16:25:43 +02:00
} ;
2021-11-08 20:24:26 +01:00
result . AddIfNotIn ( recurringAppointment ) ;
2019-07-25 14:58:13 +02:00
}
}
2020-04-02 13:19:14 +02:00
}
2019-07-25 14:58:13 +02:00
2022-05-12 18:36:05 +02:00
// Es wird bei ganztägigen Serienterminen eine Minute abgezogen, damit die nicht als zweitägig angezeigt werden. Bearbeiten kann man Serientermin im MoK noch nicht.
foreach ( var app in result . Where ( w = > w . AllDay & & w . EndDate . HasValue ) )
{
app . EndDate = app . EndDate . Value . AddMinutes ( - 1 ) ;
}
2021-11-08 20:24:26 +01:00
return result ;
2019-07-25 14:58:13 +02:00
}
[Authorize]
2020-04-02 13:19:14 +02:00
[HttpPost]
public ActionResult InsertOrUpdateAppointment ( FormCollection formCollection )
2019-07-25 14:58:13 +02:00
{
try
{
2023-02-01 20:41:13 +01:00
if ( Model is null )
2019-07-25 14:58:13 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
2019-07-25 14:58:13 +02:00
}
2020-09-21 11:57:10 +02:00
var rawStartDate = formCollection [ FormCollectionConstants . AppointmentStartDateKey ] ;
var rawEndDate = formCollection [ FormCollectionConstants . AppointmentEndDateKey ] ;
2025-01-17 16:21:58 +01:00
var subject = formCollection [ FormCollectionConstants . AppointmentSubjectKey ] ? ? string . Empty ;
var location = formCollection [ FormCollectionConstants . AppointmentLocationKey ] ? ? string . Empty ;
var notice = formCollection [ FormCollectionConstants . AppointmentNoticeKey ] ? ? string . Empty ;
2019-07-25 14:58:13 +02:00
2025-01-17 16:21:58 +01:00
subject = subject . RemoveUppercaseEsszett ( ) ;
2023-03-14 16:12:52 +01:00
location = location . RemoveUppercaseEsszett ( ) ;
2025-01-17 16:21:58 +01:00
notice = notice . RemoveUppercaseEsszett ( ) ;
2023-03-14 16:12:52 +01:00
2025-01-17 16:21:58 +01:00
var isPrivate = formCollection [ FormCollectionConstants . AppointmentIsPrivateKey ] = = "on" ;
var allDay = formCollection [ FormCollectionConstants . AppointmentIsAllDayKey ] = = "on" ;
2022-02-10 11:06:03 +01:00
2025-01-17 16:21:58 +01:00
var startAndEnd = ConvertStringDatesToDateTimes ( rawStartDate , rawEndDate ) ;
2020-06-29 19:24:24 +02:00
var startDate = startAndEnd . StartDate ;
var endDate = startAndEnd . EndDate ;
2025-01-17 16:21:58 +01:00
var appointmentToInsert = Model . SelectedAppointment ? ? new SchedulerAppointmentDC ( ) ;
2020-04-02 13:19:14 +02:00
2025-01-17 16:21:58 +01:00
var isNew = ! appointmentToInsert . SchedulerAppointmentOid . HasValue ;
2020-06-29 19:24:24 +02:00
2025-01-17 16:21:58 +01:00
var appointmentEmployeeList = new List < Employee2SchedulerAppointmentDC > ( ) ;
if ( Model . SelectedEmployees ? . Any ( ) ? ? false )
{
foreach ( var employee in Model . SelectedEmployees )
2021-11-08 20:24:26 +01:00
{
2025-01-17 16:21:58 +01:00
var employee2Appointment = new Employee2SchedulerAppointmentDC
2021-11-08 20:24:26 +01:00
{
2025-01-17 16:21:58 +01:00
Employee = employee ,
} ;
2021-11-08 20:24:26 +01:00
2025-01-17 16:21:58 +01:00
appointmentEmployeeList . Add ( employee2Appointment ) ;
2021-11-08 20:24:26 +01:00
}
2025-01-17 16:21:58 +01:00
}
2021-11-08 20:24:26 +01:00
2025-01-17 16:21:58 +01:00
if ( allDay )
{
startDate = startDate . Date ;
endDate = endDate . AddDays ( 1 ) ;
}
2023-02-01 20:41:13 +01:00
2025-01-17 16:21:58 +01:00
appointmentToInsert . EmployeeList = appointmentEmployeeList ;
appointmentToInsert . CustomerList = Model . SelectedCustomers ;
appointmentToInsert . ResourceList = Model . SelectedResources ? ? new List < ResourceDC > ( ) ;
appointmentToInsert . SupportConceptList = isNew ? new List < CompactSupportConceptDC > ( ) : appointmentToInsert . SupportConceptList ;
appointmentToInsert . ServiceRecordList = isNew ? new List < ServiceRecordDC > ( ) : appointmentToInsert . ServiceRecordList ;
appointmentToInsert . EndDate = endDate ;
appointmentToInsert . StartDate = startDate ;
appointmentToInsert . Subject = subject ;
appointmentToInsert . Description = notice ;
2025-06-11 22:56:25 +02:00
appointmentToInsert . Originator = LoggedInUser . Employee ;
2025-01-17 16:21:58 +01:00
appointmentToInsert . Location = location ;
appointmentToInsert . ActivationType = ActivationTypeId . Active ;
appointmentToInsert . IsPrivate = isPrivate ;
appointmentToInsert . AllDay = allDay ;
// Eine Minute addieren, wenn die Uhrzeit eines ganztägigen Termins nicht exakt 00:00 ist.
// ToDo: Wird beim SelectAppointmentToEdit gemacht, damit die Formularanzeige korrekt ist!
if ( allDay & & endDate . Hour = = 23 & & endDate . Minute = = 59 )
{
appointmentToInsert . EndDate = endDate . AddMinutes ( 1 ) ;
}
// ToDo: Rechte beachten!
if ( appointmentToInsert . CanBeEdited )
{
if ( ! isNew )
2022-05-12 18:36:05 +02:00
{
2025-01-17 16:21:58 +01:00
KalenderService . UpdateSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointmentToInsert } ) ;
2022-05-12 18:36:05 +02:00
}
2025-01-17 16:21:58 +01:00
else
2020-04-02 13:19:14 +02:00
{
2025-01-17 16:21:58 +01:00
KalenderService . InsertSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointmentToInsert } ) ;
2020-04-02 13:19:14 +02:00
}
}
2019-07-25 14:58:13 +02:00
}
2023-02-01 20:41:13 +01:00
catch ( Exception exception )
2019-07-25 14:58:13 +02:00
{
2020-04-02 13:19:14 +02:00
Log . Error ( exception . Message , exception ) ;
}
finally
{
2023-02-01 20:41:13 +01:00
if ( Model ! = null )
2020-04-02 13:19:14 +02:00
{
2023-03-29 19:54:16 +02:00
Model . IsAllDay = false ;
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = null ;
Model . SelectedResourceOids ? . Clear ( ) ;
Model . SelectedCustomerOids ? . Clear ( ) ;
Model . SelectedEmployeeOids ? . Clear ( ) ;
2020-04-02 13:19:14 +02:00
}
2019-07-25 14:58:13 +02:00
}
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Scheduler" ) ;
2019-07-25 14:58:13 +02:00
}
[Authorize]
2020-04-02 13:19:14 +02:00
[HttpPost]
public ActionResult NavigateToPreviousDate ( )
2019-07-25 14:58:13 +02:00
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2019-07-25 14:58:13 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
2020-04-02 13:19:14 +02:00
}
2019-07-25 14:58:13 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedDate = Model . SelectedDate . AddDays ( - 1 ) ;
2019-07-25 14:58:13 +02:00
2020-05-12 14:20:58 +02:00
if ( Model ! = null )
{
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = null ;
2022-08-11 15:10:01 +02:00
//Model.SelectedResources.Clear();
2020-05-12 14:20:58 +02:00
}
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Scheduler" ) ;
}
2019-07-25 14:58:13 +02:00
2020-04-02 13:19:14 +02:00
[Authorize]
[HttpPost]
public ActionResult NavigateToNextDate ( )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2020-04-02 13:19:14 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
2019-07-25 14:58:13 +02:00
}
2020-04-02 13:19:14 +02:00
Model . SelectedDate = Model . SelectedDate . AddDays ( 1 ) ;
2022-12-30 16:28:23 +01:00
if ( ! ( Model is null ) )
2020-05-12 14:20:58 +02:00
{
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = null ;
2022-08-11 15:10:01 +02:00
//Model.SelectedResources.Clear();
2020-05-12 14:20:58 +02:00
}
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Scheduler" ) ;
}
[Authorize]
[HttpPost]
public ActionResult SelectSchedulerDate ( FormCollection formCollection ) {
2023-03-03 21:54:36 +01:00
if ( Model is null )
2019-07-25 14:58:13 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
2020-04-02 13:19:14 +02:00
}
2020-09-21 11:57:10 +02:00
var rawSchedulerDate = formCollection [ FormCollectionConstants . AppointmentSchedulerDateKey ] ;
2020-04-02 13:19:14 +02:00
var schedulerDate = DateTime . ParseExact ( rawSchedulerDate , "dd.MM.yyyy" , null ) ;
Model . SelectedDate = schedulerDate ;
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = null ;
Model . SelectedResourceOids . Clear ( ) ;
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Scheduler" ) ;
}
[Authorize]
[HttpPost]
public ActionResult SelectAppointmentToEdit ( FormCollection formCollection )
{
2023-03-03 21:54:36 +01:00
if ( Model is null )
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
#if DEBUG
TempData [ TempDataConstants . ErrorMessageKey ] = "Model war null" ;
#endif
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
}
2020-09-21 11:57:10 +02:00
var rawOid = formCollection [ FormCollectionConstants . AppointmentSchedulerOidHolderKey ] ;
2020-04-02 13:19:14 +02:00
var isSuccessful = long . TryParse ( rawOid , out var appointmentOid ) ;
2023-03-03 21:54:36 +01:00
if ( ! isSuccessful )
2020-04-02 13:19:14 +02:00
{
2023-03-03 21:54:36 +01:00
return RedirectToActionPermanent ( "Scheduler" ) ;
}
2022-02-10 11:06:03 +01:00
2025-06-11 22:56:25 +02:00
LoadAppointmentsForDate ( ) ;
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = appointmentOid ;
Model . SelectedAppointment = Model . Appointments . FirstOrDefault ( app = > app . SchedulerAppointmentOid . HasValue & & app . SchedulerAppointmentOid . Value = = appointmentOid ) ;
if ( Model . SelectedAppointment ! = null )
2023-03-03 21:54:36 +01:00
{
2023-04-04 19:30:03 +02:00
if ( Model . SelectedAppointment . AllDay & & Model . SelectedAppointment . EndDate . HasValue )
2023-03-29 19:54:16 +02:00
{
Model . SelectedAppointment . EndDate = Model . SelectedAppointment . EndDate . Value . AddMinutes ( 1 ) . AddDays ( - 1 ) ;
}
2023-04-04 19:30:03 +02:00
2023-03-03 21:54:36 +01:00
Model . IsAllDay = Model . SelectedAppointment . AllDay ;
Model . IsPrivate = Model . SelectedAppointment . IsPrivate ;
2025-06-11 22:56:25 +02:00
Model . SelectedResourceOids = Model . SelectedAppointment ? . ResourceList . Select ( r = > r . ResourceOid . Value ) . ToList ( ) ? ? new List < long > ( ) ;
Model . SelectedEmployeeOids = Model . SelectedAppointment ? . EmployeeList . Select ( e2a = > e2a . Employee . EmployeeOid ) . ToList ( ) ? ? new List < long > ( ) ;
Model . SelectedCustomerOids = Model . SelectedAppointment ? . CustomerList . Select ( c = > c . CustomerOid ) . ToList ( ) ? ? new List < long > ( ) ;
2020-04-02 13:19:14 +02:00
}
return RedirectToActionPermanent ( "Scheduler" ) ;
}
2020-05-12 14:20:58 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public JsonResult ResetSelectedAppointment ( )
{
2024-11-13 19:54:49 +01:00
if ( Model ! = null )
2020-04-02 13:19:14 +02:00
{
2025-06-11 22:56:25 +02:00
Model . SelectedAppointmentOid = null ;
Model . SelectedResourceOids . Clear ( ) ;
Model . SelectedEmployeeOids . Clear ( ) ;
Model . SelectedCustomerOids . Clear ( ) ;
2022-02-10 11:06:03 +01:00
Model . IsAllDay = false ;
Model . IsPrivate = false ;
2019-07-25 14:58:13 +02:00
}
2020-04-02 13:19:14 +02:00
2025-06-11 22:56:25 +02:00
UpdateSelectedObjects ( ) ;
2020-05-12 14:20:58 +02:00
return Json ( null , JsonRequestBehavior . AllowGet ) ;
}
[Authorize]
public JsonResult CheckForOverlappingAppointments ( string startDateRaw , string endDateRaw , string startTimeRaw , string endTimeRaw )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2020-05-12 14:20:58 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2020-05-12 14:20:58 +02:00
return null ;
}
var isOverlapping = false ;
2025-06-11 22:56:25 +02:00
var oid = Model . SelectedAppointmentOid ;
2020-05-12 14:20:58 +02:00
var isSuccessfulStartDate = DateTime . TryParseExact ( startDateRaw , "dd.MM.yyyy" , null , DateTimeStyles . None , out var startDate ) ;
var isSuccessfulStartTime = DateTime . TryParseExact ( startTimeRaw , "HH:mm" , null , DateTimeStyles . None , out var startTime ) ;
var isSuccessfulEndDate = DateTime . TryParseExact ( endDateRaw , "dd.MM.yyyy" , null , DateTimeStyles . None , out var endDate ) ;
var isSuccessfulEndTime = DateTime . TryParseExact ( endTimeRaw , "HH:mm" , null , DateTimeStyles . None , out var endTime ) ;
if ( isSuccessfulStartDate & & isSuccessfulStartTime & & isSuccessfulEndDate & & isSuccessfulEndTime )
{
startDate = startDate . MergeDatesByDate ( startTime ) ;
endDate = endDate . MergeDatesByDate ( endTime ) ;
2020-06-29 19:24:24 +02:00
var customerOidList = Model . SelectedAppointment ? . CustomerList ? . Select ( customer = > customer . CustomerOid ) . ToList ( ) ? ? new List < long > ( ) ;
var employeeOidList = Model . SelectedAppointment ? . EmployeeList ? . Select ( employee2Appointment = > employee2Appointment . Employee . EmployeeOid ) . ToList ( ) ? ? new List < long > ( ) ;
var resourceOidList = Model . SelectedResources . Where ( resource = > resource . ResourceOid . HasValue ) . Select ( resource = > resource . ResourceOid . Value ) . ToList ( ) ? ? new List < long > ( ) ;
2020-05-12 14:20:58 +02:00
2025-06-11 22:56:25 +02:00
var originator = Model . SelectedAppointment ? . Originator ? ? LoggedInUser . Employee ;
2020-05-12 14:20:58 +02:00
var recurrenceId = Model . SelectedAppointment ? . RecurrenceId ? ? string . Empty ;
var recurrenceIndex = Model . SelectedAppointment ? . RecurrenceIndex ? ? 0 ;
2020-06-29 19:24:24 +02:00
isOverlapping = KalenderService . OverlappingAppointmentsExist ( startDate , endDate , employeeOidList , customerOidList , resourceOidList , originator . EmployeeOid , oid , recurrenceId , recurrenceIndex ) ;
2020-07-08 16:51:11 +02:00
2021-07-21 15:36:18 +02:00
// TODO: Serientermine überprüfen
2020-07-08 16:51:11 +02:00
if ( Model . Appointments ! = null )
{
2022-08-10 14:13:29 +02:00
foreach ( var appointment in Model . Appointments . Where ( app = > app . SchedulerAppointmentOid is null & & app . IsTask = = false ) )
2020-07-08 16:51:11 +02:00
{
}
}
2020-05-12 14:20:58 +02:00
}
return Json ( isOverlapping , JsonRequestBehavior . AllowGet ) ;
2019-07-25 14:58:13 +02:00
}
2020-06-29 19:24:24 +02:00
2020-07-15 12:15:13 +02:00
[Authorize]
2023-07-24 17:57:14 +02:00
public string CheckResourcesAvailability ( string start , string end , string resourceOids , bool allDay )
2020-06-29 19:24:24 +02:00
{
2023-07-24 17:57:14 +02:00
if ( string . IsNullOrWhiteSpace ( start ) | | string . IsNullOrWhiteSpace ( end ) | | string . IsNullOrWhiteSpace ( resourceOids ) | | Model is null )
2020-06-29 19:24:24 +02:00
{
2023-07-24 17:57:14 +02:00
return LeerzeichenFuerGetMethoden ;
}
2025-06-11 22:56:25 +02:00
if ( ! Model . HasRightToInsertRessourceAppointments )
2023-09-18 19:39:18 +02:00
{
2023-10-25 21:52:23 +02:00
return "Fehler! Sie haben nicht das Recht, Termine mit Ressourcen anzulegen!" ;
2023-09-18 19:39:18 +02:00
}
2023-07-31 15:29:16 +02:00
2023-07-24 17:57:14 +02:00
var oidList = ConvertOidStringToList ( resourceOids ) ;
2020-06-29 19:24:24 +02:00
2023-07-24 17:57:14 +02:00
foreach ( var oid in oidList )
{
if ( ! Model . ResourceCategories2Resources . Any ( a = > a . Value . All ( b = > b . ResourceOid ! = oid ) ) )
2021-05-17 14:01:06 +02:00
{
2023-07-31 15:29:16 +02:00
return LeerzeichenFuerGetMethoden ;
2021-05-17 14:01:06 +02:00
}
2023-07-24 17:57:14 +02:00
}
2021-05-17 14:01:06 +02:00
2023-07-24 17:57:14 +02:00
var dateTimes = ConvertStringDatesToDateTimes ( start , end ) ;
2020-06-29 19:24:24 +02:00
2023-07-31 15:29:16 +02:00
if ( allDay )
{
dateTimes . EndDate = dateTimes . EndDate . AddDays ( 1 ) ;
}
2020-06-29 19:24:24 +02:00
2025-06-11 22:56:25 +02:00
var info = KalenderService . CheckResourceAvailabilityWithEmployeeInformation ( dateTimes . StartDate , dateTimes . EndDate , oidList , Model . SelectedAppointmentOid , null ) ;
2023-07-24 17:57:14 +02:00
2023-07-31 15:29:16 +02:00
var result = string . Empty ;
2023-07-24 17:57:14 +02:00
2023-07-31 15:29:16 +02:00
foreach ( var kvp in info )
{
result + = $"Die Ressource \" { kvp . Key } \ " ist im ausgewählten Zeitraum {start} bis {end} bereits gebucht" ;
if ( ! kvp . Value . All ( string . IsNullOrWhiteSpace ) )
{
result + = ":<br /><br />" ;
}
2023-07-24 17:57:14 +02:00
2023-07-31 15:29:16 +02:00
foreach ( var interval in kvp . Value )
{
result + = $"{interval}<br />" ;
}
}
2023-07-24 17:57:14 +02:00
2023-07-31 15:29:16 +02:00
return result ;
2020-06-29 19:24:24 +02:00
}
2020-07-15 12:15:13 +02:00
[Authorize]
public string HasSelectedAppointment ( )
{
2025-06-11 22:56:25 +02:00
return JsonConvert . SerializeObject ( Model ? . SelectedAppointmentOid . HasValue ) ;
2020-07-15 12:15:13 +02:00
}
2021-11-08 20:24:26 +01:00
[Authorize]
[HttpPost]
public ActionResult ChangeSchedulerView ( FormCollection formCollection )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2021-11-08 20:24:26 +01:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2021-11-08 20:24:26 +01:00
return Logout ( ) ;
}
var selectedSchedulerView = formCollection [ "SelectedSchedulerView" ] ;
Model . SelectedSchedulerView = selectedSchedulerView ;
return RedirectToActionPermanent ( "Scheduler" ) ;
}
2022-02-10 11:06:03 +01:00
[Authorize]
[HttpPost]
public ActionResult FindFreeIntervals ( FormCollection formCollection )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2022-02-10 11:06:03 +01:00
return Logout ( ) ;
}
2024-11-12 18:37:23 +01:00
var durationString = formCollection [ "Duration" ] ;
var intervalStartDateString = formCollection [ "IntervalStart" ] . Substring ( 0 , 10 ) ;
var intervalStartTimeString = formCollection [ "IntervalStartTime" ] ;
var intervalEndDateString = formCollection [ "IntervalEnd" ] . Substring ( 0 , 10 ) ;
var intervalEndTimeString = formCollection [ "IntervalEndTime" ] ;
2022-02-10 11:06:03 +01:00
2025-06-11 22:56:25 +02:00
if ( int . TryParse ( durationString , out var intervalDuration ) & & DateTime . TryParse ( $"{intervalStartDateString} {intervalStartTimeString}" , out var intervalStart ) & & DateTime . TryParse ( $"{intervalEndDateString} {intervalEndTimeString}" , out var intervalEnd ) & & Model . LoggedInEmployee . EmployeeOid . HasValue )
2022-02-10 11:06:03 +01:00
{
2025-06-11 22:56:25 +02:00
var customerOids = Model . SelectedCustomerOidsForIntervalFinder . Clone ( ) ;
var employeeOids = Model . SelectedEmployeeOidsForIntervalFinder . Clone ( ) ;
var resourceOids = Model . SelectedResourceOidsForIntervalFinder . Clone ( ) ;
2022-02-10 11:06:03 +01:00
2025-06-11 22:56:25 +02:00
Model . FreeIntervals = KalenderService . FindAppointmentsInRangeForIntervalFinder ( intervalDuration , intervalStart , intervalEnd , resourceOids , customerOids , employeeOids , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2022-02-10 11:06:03 +01:00
2024-11-12 18:37:23 +01:00
Model . IntervalStartDate = intervalStart ;
Model . IntervalEndDate = intervalEnd ;
Model . IntervalDuration = intervalDuration ;
2022-02-10 11:06:03 +01:00
}
return RedirectToActionPermanent ( "Scheduler" ) ;
}
[Authorize]
public string SelectEmployeesForIntervalFinder ( string oidString )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-02-10 11:06:03 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOidsForIntervalFinder = ConvertOidStringToList ( oidString ) ;
UpdateSelectedObjects ( ) ;
2022-02-10 11:06:03 +01:00
return JsonConvert . SerializeObject ( Model . SelectedEmployeesForIntervalFinder . OrderBy ( o = > o . DetailDescription ) ) ;
}
[Authorize]
public string SelectCustomersForIntervalFinder ( string oidString )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-02-10 11:06:03 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOidsForIntervalFinder = ConvertOidStringToList ( oidString ) ;
UpdateSelectedObjects ( ) ;
2022-02-10 11:06:03 +01:00
return JsonConvert . SerializeObject ( Model . SelectedCustomersForIntervalFinder . OrderBy ( o = > o . LastNameFirstName ) ) ;
}
[Authorize]
public string SelectResourcesForIntervalFinder ( string resourceOids )
{
2023-02-01 20:41:13 +01:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-02-10 11:06:03 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedResourceOidsForIntervalFinder = ConvertOidStringToList ( resourceOids ) ;
UpdateSelectedObjects ( ) ;
2022-02-10 11:06:03 +01:00
return JsonConvert . SerializeObject ( Model . SelectedResourcesForIntervalFinder ) ;
}
[Authorize]
[HttpPost]
public ActionResult SetIsInIntervalFinderMode ( FormCollection formCollection )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2022-02-10 11:06:03 +01:00
return Logout ( ) ;
}
var newValue = ! Model . IsInIntervalFinderMode ;
Model . IsInIntervalFinderMode = newValue ;
if ( ! newValue )
{
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOidsForIntervalFinder . Clear ( ) ;
Model . SelectedCustomerOidsForIntervalFinder . Clear ( ) ;
Model . SelectedResourceOidsForIntervalFinder . Clear ( ) ;
2022-02-10 11:06:03 +01:00
}
return RedirectToActionPermanent ( "Scheduler" ) ;
}
[Authorize]
[HttpPost]
public ActionResult SelectIntervalForForm ( FormCollection formCollection )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2022-02-10 11:06:03 +01:00
return Logout ( ) ;
}
var startStr = formCollection [ "startDate" ] ;
var endStr = formCollection [ "endDate" ] ;
if ( DateTime . TryParse ( startStr , out var startDate ) & & DateTime . TryParse ( endStr , out var endDate ) )
{
Model . IsInIntervalFinderMode = false ;
var employees2Appointment = new List < Employee2SchedulerAppointmentDC > ( ) ;
Model . SelectedEmployeesForIntervalFinder . DoForEach ( employee = >
{
employees2Appointment . Add ( new Employee2SchedulerAppointmentDC
{
Employee = employee
} ) ;
} ) ;
Model . SelectedAppointment = new SchedulerAppointmentDC ( )
{
ActivationType = ActivationTypeId . Active ,
2024-11-12 18:37:23 +01:00
IsTask = false ,
IsPrivate = false ,
2025-06-11 22:56:25 +02:00
Originator = LoggedInUser . Employee ,
2024-11-12 18:37:23 +01:00
StartDate = startDate ,
EndDate = endDate
2022-02-10 11:06:03 +01:00
} ;
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOids = Model . SelectedCustomerOidsForIntervalFinder . Clone ( ) ;
Model . SelectedEmployeeOids = Model . SelectedEmployeeOidsForIntervalFinder . Clone ( ) ;
Model . SelectedResourceOids = Model . SelectedResourceOidsForIntervalFinder . Clone ( ) ;
2022-02-10 11:06:03 +01:00
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOidsForIntervalFinder . Clear ( ) ;
Model . SelectedEmployeeOidsForIntervalFinder . Clear ( ) ;
Model . SelectedResourceOidsForIntervalFinder . Clear ( ) ;
2022-02-10 11:06:03 +01:00
Model . IntervalStartDate = null ;
2024-11-12 18:37:23 +01:00
Model . IntervalEndDate = null ;
2022-02-10 11:06:03 +01:00
}
return RedirectToActionPermanent ( "Scheduler" ) ;
}
[Authorize]
public string ResetIntervalFinder ( )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2022-02-10 11:06:03 +01:00
{
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-02-10 11:06:03 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOidsForIntervalFinder . Clear ( ) ;
Model . SelectedEmployeeOidsForIntervalFinder . Clear ( ) ;
Model . SelectedResourceOidsForIntervalFinder . Clear ( ) ;
2022-02-10 11:06:03 +01:00
Model . SelectedCustomersForIntervalFinder . Clear ( ) ;
Model . SelectedEmployeesForIntervalFinder . Clear ( ) ;
Model . SelectedResourcesForIntervalFinder . Clear ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-02-10 11:06:03 +01:00
}
2022-08-10 14:13:29 +02:00
[Authorize]
public ActionResult FetchAppointments ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "OneDaySchedulerPartial" ) ;
}
2022-08-10 14:13:29 +02:00
LoadAppointmentsForDate ( ) ;
return PartialView ( "OneDaySchedulerPartial" , Model ) ;
}
2022-12-30 16:28:23 +01:00
[Authorize]
public string SelectResourcesForAppointmentFiltering ( string resourceOids )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
var oidList = ConvertOidStringToList ( resourceOids ) ;
var list = new List < ResourceDC > ( ) ;
Model . ResourceCategories2Resources . Values . DoForEach ( l = > l . DoForEach ( s = > list . AddIfNotIn ( s ) ) ) ;
Model . SelectedResourcesForFiltering = list . Where ( resource = > resource . ResourceOid . HasValue & & oidList . Contains ( resource . ResourceOid . Value ) ) . ToList ( ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedResourceOidsForFiltering = oidList ;
2022-12-30 16:28:23 +01:00
return JsonConvert . SerializeObject ( Model . SelectedResourcesForFiltering ) ;
}
[Authorize]
public string SelectEmployeesForAppointmentFiltering ( string oidString )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOidsForFiltering = ConvertOidStringToList ( oidString ) ;
2022-12-30 16:28:23 +01:00
2025-06-11 22:56:25 +02:00
return Model . SelectedEmployeeOidsForFiltering . Count . ToString ( ) ;
2022-12-30 16:28:23 +01:00
}
[Authorize]
public string SelectCustomersForAppointmentFiltering ( string oidString )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOidsForFiltering = ConvertOidStringToList ( oidString ) ;
2022-12-30 16:28:23 +01:00
2025-06-11 22:56:25 +02:00
return Model . SelectedCustomerOidsForFiltering . Count . ToString ( ) ;
2022-12-30 16:28:23 +01:00
}
[Authorize]
public ActionResult FetchSelectedEmployeesForPopup ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2022-12-30 16:28:23 +01:00
return PartialView ( "EmployeeForFilteringPartial" , Model ) ;
}
[Authorize]
public ActionResult FetchEmployeeFilteringModalBody ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2022-12-30 16:28:23 +01:00
return PartialView ( "EmployeeFilteringModalContentPartial" , Model ) ;
}
[Authorize]
public string SelectTeamForFiltering ( string teamOidString )
{
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee ? . EmployeeOid is null )
2022-12-30 16:28:23 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
if ( long . TryParse ( teamOidString , out var teamOid ) )
{
2025-06-11 22:56:25 +02:00
var team = EmployeeService . FindTeamByOid ( teamOid , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-02-09 15:17:33 +01:00
2022-12-30 16:28:23 +01:00
if ( ! ( team is null ) )
{
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOidsForFiltering . AddRangeIfElementsNotIn ( team . Member . Select ( m = > m . EmployeeOid ) ) ;
2022-12-30 16:28:23 +01:00
}
}
2025-06-11 22:56:25 +02:00
UpdateSelectedObjects ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
2025-01-17 16:21:58 +01:00
#region Mitarbeiterauswahl
2022-12-30 16:28:23 +01:00
[Authorize]
public string SelectTeamForAppointment ( string teamOidString )
{
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee ? . EmployeeOid is null )
2022-12-30 16:28:23 +01:00
{
2025-01-17 16:21:58 +01:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
var teamMemberOids = new List < long > ( ) ;
2025-01-17 16:21:58 +01:00
if ( ! long . TryParse ( teamOidString , out var teamOid ) )
2022-12-30 16:28:23 +01:00
{
2025-01-17 16:21:58 +01:00
return LeerzeichenFuerGetMethoden ;
}
2025-06-11 22:56:25 +02:00
var team = EmployeeService . FindTeamByOid ( teamOid , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2025-01-17 16:21:58 +01:00
if ( team is null )
{
return LeerzeichenFuerGetMethoden ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOids . AddRangeIfElementsNotIn ( team . Member . Select ( m = > m . EmployeeOid ) ) ;
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return LeerzeichenFuerGetMethoden ;
}
[Authorize]
public ActionResult UpdateEmployeeSelection ( string oidString )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
Logout ( ) ;
return PartialView ( "SchedulerEmployeeSelectionPartial" ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOids = ConvertOidStringToList ( oidString ) ;
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "SchedulerEmployeeSelectionPartial" , Model ) ;
}
[Authorize]
public ActionResult SelectAllEmployees ( bool isChecked )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "EmployeeSelectionPopupListPartial" ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOids = isChecked ? Model . AllEmployees . Select ( r = > r . EmployeeOid ) . ToList ( ) : new List < long > ( ) ;
2025-01-17 16:21:58 +01:00
2025-06-11 22:56:25 +02:00
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "EmployeeSelectionPopupListPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedEmployees ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "SchedulerEmployeeSelectionPartial" ) ;
}
return PartialView ( "SchedulerEmployeeSelectionPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedEmployeePopupList ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "EmployeeSelectionPopupListPartial" ) ;
}
return PartialView ( "EmployeeSelectionPopupListPartial" , Model ) ;
}
#endregion
#region Klientenauswahl
[Authorize]
public ActionResult SelectAllCustomers ( bool isChecked )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
Logout ( ) ;
return PartialView ( "CustomerSelectionPopupListPartial" ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOids = isChecked ? Model . AllCustomers . Select ( r = > r . CustomerOid ) . ToList ( ) : new List < long > ( ) ;
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "CustomerSelectionPopupListPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedCustomers ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "SchedulerCustomerSelectionPartial" ) ;
}
return PartialView ( "SchedulerCustomerSelectionPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedCustomerPopupList ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "CustomerSelectionPopupListPartial" ) ;
}
return PartialView ( "CustomerSelectionPopupListPartial" , Model ) ;
}
[Authorize]
public ActionResult UpdateCustomerSelection ( string oidString )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
Logout ( ) ;
return PartialView ( "SchedulerCustomerSelectionPartial" ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedCustomerOids = ConvertOidStringToList ( oidString ) ;
2025-01-17 16:21:58 +01:00
2025-06-11 22:56:25 +02:00
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "SchedulerCustomerSelectionPartial" , Model ) ;
}
#endregion
#region Ressourcenauswahl
[Authorize]
public ActionResult UpdateResourceSelection ( string oidString )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "SchedulerResourceSelectionPartial" ) ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
2025-01-17 16:21:58 +01:00
//var list = new List<ResourceDC>();
//Model.ResourceCategories2Resources.Values.DoForEach(l => l.DoForEach(s => list.AddIfNotIn(s)));
//Model.SelectedResources = list.Where(resource => resource.ResourceOid.HasValue && oidList.Contains(resource.ResourceOid.Value)).ToList();
2025-06-11 22:56:25 +02:00
Model . SelectedResourceOids = ConvertOidStringToList ( oidString ) ;
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "SchedulerResourceSelectionPartial" , Model ) ;
2022-12-30 16:28:23 +01:00
}
2025-01-17 16:21:58 +01:00
[Authorize]
public ActionResult SelectAllResources ( bool isChecked )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "ResourceSelectionPopupListPartial" ) ;
}
2025-06-11 22:56:25 +02:00
Model . SelectedResourceOids = isChecked ? Model . AllResources . Select ( r = > r . ResourceOid . Value ) . ToList ( ) : new List < long > ( ) ;
UpdateSelectedObjects ( ) ;
2025-01-17 16:21:58 +01:00
return PartialView ( "ResourceSelectionPopupListPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedResourcePopupList ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "ResourceSelectionPopupListPartial" ) ;
}
return PartialView ( "ResourceSelectionPopupListPartial" , Model ) ;
}
[Authorize]
public ActionResult LoadUpdatedResources ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2025-01-17 16:21:58 +01:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "SchedulerResourceSelectionPartial" ) ;
}
return PartialView ( "SchedulerResourceSelectionPartial" , Model ) ;
}
#endregion
2022-12-30 16:28:23 +01:00
[Authorize]
public ActionResult FetchCustomersForFiltering ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2022-12-30 16:28:23 +01:00
return PartialView ( "CustomerFilterSelectionPartial" , Model ) ;
}
[Authorize]
public ActionResult FetchCustomerFilteringModalBody ( )
{
2025-06-11 22:56:25 +02:00
if ( Model is null )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2022-12-30 16:28:23 +01:00
return PartialView ( "CustomerFilteringModalContentPartial" , Model ) ;
}
[Authorize]
public string SetShouldLoadTasks ( bool isChecked )
{
try
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
Model . ShouldLoadTasks = isChecked ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
[Authorize]
2023-03-03 21:54:36 +01:00
public string DeleteAppointment ( string appointmentIdentifier , bool deleteSeries )
2022-12-30 16:28:23 +01:00
{
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee ? . EmployeeOid is null )
2022-12-30 16:28:23 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
2025-06-11 22:56:25 +02:00
LoadAppointmentsForDate ( ) ;
var schedulerAppointment = Model . AppointmentListItems . FirstOrDefault ( app = > app . Identifier . Equals ( appointmentIdentifier ) ) ? . SchedulerAppointment ;
2023-03-03 21:54:36 +01:00
if ( schedulerAppointment is null )
2022-12-30 16:28:23 +01:00
{
2023-03-03 21:54:36 +01:00
return LeerzeichenFuerGetMethoden ;
}
2022-12-30 16:28:23 +01:00
2023-03-03 21:54:36 +01:00
if ( schedulerAppointment . SchedulerAppointmentOid is null & & ! ( schedulerAppointment . RecurrenceInfo is null ) )
{
var recurrenceInfo = new RecurrenceInfo ( ) ;
recurrenceInfo . FromXml ( schedulerAppointment . RecurrenceInfo ) ;
2022-12-30 16:28:23 +01:00
2023-03-03 21:54:36 +01:00
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
pattern . RecurrenceInfo . FromXml ( schedulerAppointment . RecurrenceInfo ) ;
pattern . Start = pattern . RecurrenceInfo . Start ;
pattern . End = pattern . RecurrenceInfo . End ;
2022-12-30 16:28:23 +01:00
2023-03-03 21:54:36 +01:00
var exception = pattern . CreateException ( AppointmentType . DeletedOccurrence , schedulerAppointment . RecurrenceIndex ) ;
var recurrenceId = exception . RecurrenceInfo . Id . ToString ( ) ;
schedulerAppointment = deleteSeries ?
KalenderService . FindRootAppointmentByRecurrenceId ( recurrenceId ) :
CloneAppointment ( schedulerAppointment , $"<RecurrenceInfo Id=\" { recurrenceId } \ " Index=\"{schedulerAppointment.RecurrenceIndex}\" />" , ( int ) exception . Type ) ;
}
if ( schedulerAppointment is null )
{
return LeerzeichenFuerGetMethoden ;
}
2025-06-11 22:56:25 +02:00
var teamMemberCustomerOids = EmployeeService . LoadTeamsRelatedCustomerOids ( Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-03-03 21:54:36 +01:00
var customerList = schedulerAppointment . CustomerList ;
var employeeList = schedulerAppointment . EmployeeList ;
var resourceList = schedulerAppointment . ResourceList ;
var originator = schedulerAppointment . Originator ;
var isNew = schedulerAppointment . SchedulerAppointmentOid is null ;
2025-06-11 22:56:25 +02:00
var loggedOnUser = LoggedInUser ;
2023-03-03 21:54:36 +01:00
var isAllowedToDelete = BS . Shared . Core . Utils . CheckSchedulerRights ( customerList , resourceList , employeeList , originator , isNew , SchedulerRightsCheckType . Edit , loggedOnUser , teamMemberCustomerOids ) ;
if ( isAllowedToDelete )
{
if ( schedulerAppointment . SchedulerAppointmentOid . HasValue & & schedulerAppointment . NewSchedulerAppointmentVersion . HasValue )
2022-12-30 16:28:23 +01:00
{
2023-03-03 21:54:36 +01:00
var oid2Version = new Dictionary < long , long > { { schedulerAppointment . SchedulerAppointmentOid . Value , schedulerAppointment . NewSchedulerAppointmentVersion . Value } } ;
2022-12-30 16:28:23 +01:00
KalenderService . DeactivateSchedulerAppointments ( oid2Version ) ;
}
2023-03-03 21:54:36 +01:00
// DeletedOccurrence
if ( schedulerAppointment . Type = = 4 & & ! deleteSeries )
{
KalenderService . InsertSchedulerAppointments ( new List < SchedulerAppointmentDC > { schedulerAppointment } ) ;
}
2022-12-30 16:28:23 +01:00
}
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
2023-02-09 15:17:33 +01:00
2023-03-03 21:54:36 +01:00
[Authorize]
public static SchedulerAppointmentDC CloneAppointment ( SchedulerAppointmentDC schedulerAppointment , string recurrenceInfo , int type )
{
return new SchedulerAppointmentDC
{
StartDate = schedulerAppointment . StartDate ,
EndDate = schedulerAppointment . EndDate ,
ServiceRecordList = schedulerAppointment . ServiceRecordList ? ? new List < ServiceRecordDC > ( ) ,
EmployeeList = schedulerAppointment . EmployeeList ? ? new List < Employee2SchedulerAppointmentDC > ( ) ,
ActivationType = ActivationTypeId . Active ,
AllDay = schedulerAppointment . AllDay ,
CanBeEdited = schedulerAppointment . CanBeEdited ,
CompletedDate = schedulerAppointment . CompletedDate ,
CompletedNotice = schedulerAppointment . CompletedNotice ,
CompletedUser = schedulerAppointment . CompletedUser ,
CustomerList = schedulerAppointment . CustomerList ? ? new List < CompactCustomerDC > ( ) ,
2023-03-14 16:12:52 +01:00
Description = schedulerAppointment . Description ? . RemoveUppercaseEsszett ( ) ,
2023-03-03 21:54:36 +01:00
DueDate = schedulerAppointment . DueDate ,
FormerBookingSequenceOid = schedulerAppointment . FormerBookingSequenceOid ,
FormerTaskOid = schedulerAppointment . FormerTaskOid ,
HasServiceRecordEntry = schedulerAppointment . HasServiceRecordEntry ,
IsPrivate = schedulerAppointment . IsPrivate ,
IsTask = schedulerAppointment . IsTask ,
IsTeilnahmeBestaetigung = schedulerAppointment . IsTeilnahmeBestaetigung ,
LabelKey = schedulerAppointment . LabelKey ,
2023-03-14 16:12:52 +01:00
Location = schedulerAppointment . Location ? . RemoveUppercaseEsszett ( ) ,
2023-03-03 21:54:36 +01:00
Originator = schedulerAppointment . Originator ,
RecurrenceInfo = recurrenceInfo ,
ReminderInfo = schedulerAppointment . ReminderInfo ,
ResourceList = schedulerAppointment . ResourceList ? ? new List < ResourceDC > ( ) ,
Status = schedulerAppointment . Status ,
2023-03-14 16:12:52 +01:00
Subject = schedulerAppointment . Subject ? . RemoveUppercaseEsszett ( ) ? ? string . Empty ,
2023-03-03 21:54:36 +01:00
SupportConceptList = schedulerAppointment . SupportConceptList ? ? new List < CompactSupportConceptDC > ( ) ,
TaskDescription = schedulerAppointment . TaskDescription ,
Type = type
} ;
}
2023-02-09 15:17:33 +01:00
[Authorize]
public string SelectTeamForIntervalFinder ( string teamOidString )
{
2025-06-11 22:56:25 +02:00
if ( Model ? . LoggedInEmployee ? . EmployeeOid is null )
2023-02-09 15:17:33 +01:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-02-09 15:17:33 +01:00
}
if ( long . TryParse ( teamOidString , out var teamOid ) )
{
2025-06-11 22:56:25 +02:00
var team = EmployeeService . FindTeamByOid ( teamOid , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-02-09 15:17:33 +01:00
if ( ! ( team is null ) )
{
var memberOids = team . Member . Select ( member = > member . EmployeeOid ) . ToList ( ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOidsForIntervalFinder . AddRangeIfElementsNotIn ( memberOids ) ;
2023-02-09 15:17:33 +01:00
return JsonConvert . SerializeObject ( memberOids ) ;
}
}
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2023-02-09 15:17:33 +01:00
}
2023-02-23 11:48:41 +01:00
[Authorize]
[HttpPost]
public ActionResult TransformAppointmentToServiceRecord ( FormCollection formCollection )
{
if ( Model is null )
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-02-23 11:48:41 +01:00
return Logout ( ) ;
}
2025-06-11 22:56:25 +02:00
var identifier = formCollection [ FormCollectionConstants . AppointmentIdInputKey ] ;
if ( Model . AppointmentListItems = = null )
2023-02-23 11:48:41 +01:00
{
2025-06-11 22:56:25 +02:00
LoadAppointmentsForDate ( ) ;
2023-03-03 21:54:36 +01:00
}
var appointmentListItem = Model . AppointmentListItems . FirstOrDefault ( f = > f . Identifier . Equals ( identifier ) ) ;
2023-02-23 11:48:41 +01:00
2023-03-03 21:54:36 +01:00
if ( appointmentListItem is null )
{
return RedirectToActionPermanent ( "PrepareServiceRecordInsert" , "Main" ) ;
}
2023-02-23 11:48:41 +01:00
2023-03-03 21:54:36 +01:00
var appointment = appointmentListItem . SchedulerAppointment ;
2023-02-23 11:48:41 +01:00
2025-06-11 22:56:25 +02:00
//var employeeOids = appointment.EmployeeList.Select(employee2Appointment => employee2Appointment.Employee.EmployeeOid).ToList();
//if(employeeOids.Count == 0)
//{
// employeeOids.Add(appointment.Originator.EmployeeOid);
//}
2023-02-23 11:48:41 +01:00
2025-06-11 22:56:25 +02:00
TempData [ TempDataConstants . AppointmentOidKey ] = appointmentListItem . SchedulerAppointment ? . SchedulerAppointmentOid ;
2023-03-03 21:54:36 +01:00
2025-06-27 13:11:10 +02:00
2023-02-23 11:48:41 +01:00
return RedirectToActionPermanent ( "PrepareServiceRecordInsert" , "Main" ) ;
2025-03-25 17:36:15 +01:00
}
2023-03-03 21:54:36 +01:00
2025-03-25 17:36:15 +01:00
[Authorize]
public override string SaveCollapsibleStatus ( bool isOpen , string identifier )
{
Model . Collapsibles2IsShown [ identifier ] = isOpen ;
return LeerzeichenFuerGetMethoden ;
2023-02-23 11:48:41 +01:00
}
2019-07-25 14:58:13 +02:00
}
}