using BeWoPlanerMobil.Models; using BeWoPlanerMobil.Service; using BeWoPlanerMobil.Util; using BeWoPlanerMobil.Util.Constants; using BeWoPlanerMobil.Util.SchedulerUtils; using BeWoPlanerMobil.Views.DevExpressScheduler; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using DevExpress.Web.Mvc; using DevExpress.XtraScheduler; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using CompactCustomerDC = BS.Shared.DataContracts.Compact.CompactCustomerDC; namespace BeWoPlanerMobil.Controllers { /* * ToDo: * Übersetzungen */ public class DevExpressSchedulerController : AbstractBaseController { [Authorize] public override string SaveCollapsibleStatus(bool isOpen, string identifier) { return SaveCollapsibleStatusToModel(Model, isOpen, identifier); } private DevExpressSchedulerModel _Model; public DevExpressSchedulerModel Model { get { if(false == MobileSessionFacade.IsUserLoggedIn()) { Logout(); return null; } if(_Model != null) { return _Model; } _Model = new DevExpressSchedulerModel(); InitModel(_Model); InitViewModel(); return _Model; } } private AppointmentModel _AppointmentModel; public AppointmentModel AppointmentModel { get { if(false == MobileSessionFacade.IsUserLoggedIn()) { Logout(); return null; } if(_AppointmentModel != null) { return _AppointmentModel; } _AppointmentModel = new AppointmentModel(); InitModel(_AppointmentModel); InitAppointmentModel(); return _AppointmentModel; } } private void InitAppointmentModel() { AppointmentModel.PossibleEmployees = EmployeeService.GetAllAuthorizedCompactEmployees(); AppointmentModel.PossibleCustomers = CustomerService.GetAllAuthorizedCompactCustomers(); AppointmentModel.PossibleResources = KalenderService.GetAllResources(); AppointmentModel.ResourceCategories2Resources = new Dictionary>(); foreach(var resource in AppointmentModel.PossibleResources) { AppointmentModel.ResourceCategories2Resources.AddOrUpdateValueInDictionary(resource.ResourceCategory, resource); } } private void InitViewModel() { if(false == MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer") || Model?.LoggedInUser?.Employee is null) { Logout(); return; } var user = Model.LoggedInUser; var compactEmployee = user.Employee; var employeeOid = compactEmployee.EmployeeOid; var userSettings = user.Settings.FirstOrDefault(f => f.Type.Equals(SettingsType.ApplicationSettings))?.Value; Model.ShowOnlyMyOwnAppointments = UserSettingsUtils.GetSettingValueAsBool(userSettings, SettingsKeys.ZeigeNurMeineTermine); if(Model.ShowOnlyMyOwnAppointments) { Model.SelectedEmployeeOidsForFiltering = new List { employeeOid }; } // Nach den Kalenderrechten filtern! Model.PossibleEmployees = EmployeeService.GetAllAuthorizedCompactEmployees(); Model.PossibleCustomers = CustomerService.GetAllAuthorizedCompactCustomers(); Model.PossibleResources = KalenderService.GetAllResources(); // Ressourcen if(Model.HasRightToInsertRessourceAppointments || Model.HasRightToViewAllResourceAppointments) { var allResources = KalenderService.GetAllResources().OrderBy(r => r.Name).ToList(); var categories2Resources = new Dictionary>(); foreach(var category in allResources.Select(resource => resource.ResourceCategory)) { categories2Resources.AddOrUpdateValueInDictionary(category, allResources.Where(resource => resource.ResourceCategory.Equals(category)).OrderBy(r => r.Name).ToList()); } Model.ResourceCategories2Resources = categories2Resources.OrderBy(category2Resources => category2Resources.Key.DisplayName).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } // Teams Model.MyTeamEmployees = EmployeeService.GetAllTeamMember(compactEmployee).OrderBy(employee => employee.LastName).ToList(); if(Model.HasRightToViewTeams) { Model.MyTeams = EmployeeService.GetAllActiveCompactTeamsForEmployee(employeeOid).OrderBy(team => team.Name).ToList(); } Model.TeamMemberCustomerOids = EmployeeService.LoadTeamsRelatedCustomerOids(employeeOid); // /Teams Model.SelectedEmployeesForFiltering = Model.PossibleEmployees.Where(possibleEmployee => Model.SelectedEmployeeOidsForFiltering?.Contains(possibleEmployee.EmployeeOid) ?? false).ToList(); Model.SelectedCustomersForFiltering = Model.PossibleCustomers.Where(possibleCustomer => Model.SelectedCustomerOidsForFiltering?.Contains(possibleCustomer.CustomerOid) ?? false).ToList(); Model.SelectedResourcesForFiltering = Model.PossibleResources.Where(possibleResource => possibleResource.ResourceOid.HasValue && (Model.SelectedResourceOidsForFiltering?.Contains(possibleResource.ResourceOid.Value) ?? false)).ToList(); ReloadAppointments(); } private void ReloadAppointments() { if(Model.LoggedInEmployee.EmployeeOid is null) { throw new Exception("Bei DevExpressSchedulerController.ReloadAppointments() ist die Oid des angemeldeten Benutzers wider Erwarten NULL!"); } UpdateSelectedObjects(); var user = LoggedInUser; var employeeOid = user.Employee.EmployeeOid; var userSettings = user.Settings.FirstOrDefault(f => f.Type.Equals(SettingsType.ApplicationSettings))?.Value; var relatedCustomerOids = user.Employee.RelatedCustomerOIDList; Model.CurrentViewType = (SchedulerViewType) UserSettingsUtils.GetSettingValueAsInteger(userSettings, SettingsKeys.SchedulerViewType); var intervalStart = DateTimeExtensions.GetDayOfWeek(DayOfWeek.Monday); var intervalEnd = intervalStart.AddDays(7); var allAppointments = KalenderService.LoadFilteredAppointmentsMitAufgabenForMoK ( Model.HasRightKalenderMitarbeitertermineAnsehen, employeeOid, intervalStart, intervalEnd, Model.SelectedEmployeeOidsForFiltering, Model.SelectedCustomerOidsForFiltering, Model.SelectedResourceOidsForFiltering, Model.ShowOnlyEmployees, Model.ShowOnlyCustomers, Model.ShowOnlyResources, Model.ShowOnlyPrivateAppointments, Model.ShowOnlyMyOwnAppointments, Model.ShowTasks ); var appointments = allAppointments; var changedOrDeletedOccurrences = KalenderService.FindAppointmentsByRecurrenceId(appointments.Select(apt => apt.RecurrenceId).ToList(), true); Model.RecurrenceIdsWithOccurrences = new List(); foreach(var occ in changedOrDeletedOccurrences) { Model.RecurrenceIdsWithOccurrences.AddIfNotIn(occ.RecurrenceIdReference); } foreach(var appointment in appointments) { if(false == appointment.IsPrivate || appointment.Originator.EmployeeOid.Equals(employeeOid) || appointment.EmployeeList.Any(e => e.Employee.EmployeeOid.Equals(employeeOid))) { continue; } appointment.Description = "Privater Termin"; appointment.Subject = $"Privat ({appointment.Originator})"; appointment.CanBeDeleted = false; appointment.CanBeEdited = false; appointment.CanBeViewed = false; } // Den Rechten entsprechend filtern if(Model.HasRightKalenderKliententermineAnsehen is false) { var relatedCustomers = Model.LoggedInEmployee.RelatedCustomers.Select(s => s.Customer); var filteredAppointments = new List(); // Nur die der eigenen Klienten nicht filtern? appointments = appointments.Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && appointment.CustomerList.Any(customer => relatedCustomers.Contains(customer)) || appointment.CustomerList.Count == 0 ).ToList(); foreach(var appointment in appointments) { if(appointment.CustomerList.Any() && false == appointment.CustomerList.Any(customer => relatedCustomers.Contains(customer))) { continue; } filteredAppointments.Add(appointment); } appointments = filteredAppointments; } if(Model.HasRightKalenderMitarbeitertermineAnsehen is false) { appointments = appointments.Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && (appointment.Originator.Equals(Model.LoggedInCompactEmployee) ||appointment.EmployeeList.Any(employee2Appointment => employee2Appointment.Employee.Equals(Model.LoggedInCompactEmployee))) ).ToList(); } if(Model.HasRightKalenderRessourcentermineAnsehen is false) { appointments = appointments.Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && appointment.ResourceList.Count == 0 ).ToList(); } if(Model.ShowTasks is false) { appointments = appointments.Where(appointment => appointment.IsTask is false).ToList(); } else { appointments.AddRangeIfElementsNotIn(allAppointments.Where(appointment => appointment.IsTask)); } if(Model.ShowEmployeeColors) { appointments.DoForEach(appointment => appointment.ShowEmployeeColors = true); } var customerAbsenceTimes = KalenderService.GetAllActiveCustomersAbsenceTimesInInterval(intervalStart, intervalEnd, employeeOid, Model.SelectedCustomerOidsForFiltering); var employeeAbsenceTimes = KalenderService.GetAllActiveEmployeeAbsenceTimesInInterval(intervalStart, intervalEnd, employeeOid, Model.SelectedEmployeeOidsForFiltering); if(Model.ShowAbsenceTimes) { var allAbsenceTimes = new List(); allAbsenceTimes.AddRange(customerAbsenceTimes); allAbsenceTimes.AddRange(employeeAbsenceTimes); appointments.AddRange(ConvertAbsenceTimesToAppointments(allAbsenceTimes, Model.PossibleCustomers, Model.PossibleEmployees)); } if(Model.HasRightKalenderRessourcenTermineAndererAendern is false) { appointments .Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && appointment.Originator.Equals(Model.LoggedInCompactEmployee) is false && appointment.ResourceList.Any()) .DoForEach(appointment => appointment.CanBeEdited = false); } if(Model.HasRightKalenderKlientenTermineAendern is false) { appointments .Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && appointment.Originator.Equals(Model.LoggedInCompactEmployee) is false && appointment.CustomerList.Any()) .DoForEach(appointment => appointment.CanBeEdited = false); } if(Model.HasRightKalenderMitarbeiterTermineAendern is false) { appointments .Where(appointment => appointment.IsTask is false && appointment.IsAbsenceTime is false && appointment.Originator.Equals(Model.LoggedInCompactEmployee) is false) .DoForEach(appointment => appointment.CanBeEdited = false); } foreach(var appointment in appointments.Where(apt => apt.IsTask is false && apt.IsAbsenceTime is false && apt.Originator.Equals(Model.LoggedInCompactEmployee) is false && apt.CustomerList.Any())) { var canEdit = appointment.CanBeEdited; var canView = appointment.CanBeViewed; var canDelete = appointment.CanBeDeleted; var subject = appointment.Subject; } var x = appointments.Where(w => w.SchedulerAppointmentOid is null).ToList(); Model.Appointments = appointments; LoadNotificationCount(); } [Authorize] public ActionResult GetNotifications() { LoadNotificationCount(); return PartialView("SchedulerNotificationPartial", Model); } private void LoadNotificationCount() { var openAppointments = KalenderService.GetAllOpenAppointmentsForEmployee(LoggedInUser.Employee.EmployeeOid).OrderBy(openAppointment => openAppointment.StartDate).ToList(); var employee2Appointments = new List(); foreach(var appointment in openAppointments) { // Termine, die von anderen Beantwortet wurden: employee2Appointments.AddRangeIfElementsNotIn(appointment.EmployeeList.Where(e2a => appointment.Originator.Equals(Model.LoggedInCompactEmployee) && false == e2a.Employee.Equals(Model.LoggedInCompactEmployee) && e2a.IsPChanged && e2a.IsPC_CheckedTs is null && e2a.ParticipationAnswer != ParticipationAnswer.Offen && e2a.ParticipationAnswer != ParticipationAnswer.Verstrichen )); // Termine zum Beantworten: employee2Appointments.AddRangeIfElementsNotIn(appointment.EmployeeList.Where(e2A => false == appointment.Originator.Equals(Model.LoggedInCompactEmployee) && false == e2A.IsPChanged && e2A.Employee.Equals(Model.LoggedInCompactEmployee) )); } Model.OpenEmployee2AppointmentRels = new List(); Model.OpenEmployee2AppointmentRelOids = new List(); Model.OpenAppointments = openAppointments; Model.OpenAppointmentOids = openAppointments .Where(schedulerAppointment => schedulerAppointment.SchedulerAppointmentOid.HasValue) .Select(schedulerAppointment => schedulerAppointment.SchedulerAppointmentOid.Value) .ToList(); Model.OpenEmployee2AppointmentRels.AddRange(employee2Appointments); Model.OpenEmployee2AppointmentRelOids = employee2Appointments.Where(w => w.Employee2SchedulerAppointmentOid.HasValue).Select(s => s.Employee2SchedulerAppointmentOid.Value).ToList(); } private List ConvertAbsenceTimesToAppointments(List absenceTimes, List allCustomers, List allEmployees) { var appointments = new List(); foreach(var absenceTime in absenceTimes) { var subject = $"{absenceTime.Reason.Description}"; var employee = absenceTime.EmployeeOid.HasValue ? allEmployees.FirstOrDefault(f => f.EmployeeOid == absenceTime.EmployeeOid.Value) : null; var customer = absenceTime.CustomerOid.HasValue ? allCustomers.FirstOrDefault(f => f.CustomerOid == absenceTime.CustomerOid.Value) : null; var allDay = absenceTime.IsAllDay; var isEmployeeAbsenceTime = absenceTime.EmployeeOid.HasValue; IFilterableDC dc = employee; var originator = employee; if(false == isEmployeeAbsenceTime) { dc = customer; originator = EmployeeService.FindCompactEmployeeByFullname(absenceTime.InsUser); } if(false == dc is null) { subject += $" ({dc.SimpleDescription})"; } var absenceTimeEnd = absenceTime.End; var end = absenceTime.End ?? DateTime.MaxValue; var isMultipleDayAbsenceTime = absenceTime.End is null || absenceTime.Start.Value.Date != absenceTime.End.Value.Date; if(isMultipleDayAbsenceTime && allDay && end != DateTime.MaxValue) { absenceTimeEnd = end.AddDays(1); } if(originator is null) { originator = LoggedInUser.Employee; } var appointment = new SchedulerAppointmentDC { AbsenceReason = absenceTime.Reason, AllDay = true, Description = absenceTime.Notice, StartDate = absenceTime.Start, EndDate = absenceTimeEnd, ActivationType = ActivationTypeId.Active, FormerAbsenceTimeOid = absenceTime.AbsenceTimeOid, Originator = originator, Subject = subject, Krankheitsmeldung = absenceTime.KrankheitsMeldung, IsAbsenceTime = true }; if(false == customer is null && employee is null) { appointment.CustomerList = new List { customer }; } appointments.Add(appointment); } return appointments; } [Authorize] public ActionResult DevExpressScheduler() { if(false == MobileSessionFacade.IsUserLoggedIn() || Model is null) { return RedirectToActionPermanent("Index", "Login"); } Model.Resources = new List(); return View(Model); } [Authorize] public ActionResult SchedulerPagePartial() { return PartialView("SchedulerPagePartial", Model); } [Authorize] public ActionResult EditAppointment() { UpdateAppointment(); return PartialView("SchedulerPagePartial", Model); } [Authorize] private void UpdateAppointment() { var appointmentsToInsert = SchedulerExtension.GetAppointmentsToInsert( "scheduler", Model.Appointments, SchedulerHelper.DefaultAppointmentStorage, SchedulerHelper.DefaultResourceStorage); var appointmentsToUpdate = SchedulerExtension.GetAppointmentsToUpdate( "scheduler", Model.Appointments, SchedulerHelper.DefaultAppointmentStorage, SchedulerHelper.DefaultResourceStorage ); var appointmentsToRemove = SchedulerExtension.GetAppointmentsToRemove( "scheduler", Model.Appointments, SchedulerHelper.DefaultAppointmentStorage, SchedulerHelper.DefaultResourceStorage ); foreach(var appointment in appointmentsToInsert) { if(appointment.Type != (int) AppointmentType.DeletedOccurrence && appointment.Type != (int) AppointmentType.ChangedOccurrence) { appointment.CustomerList = AppointmentModel.SelectedCustomers; appointment.ResourceList = AppointmentModel.SelectedResources; appointment.EmployeeList = new List(); foreach(var selectedEmployee in AppointmentModel.SelectedEmployees ?? new List()) { appointment.EmployeeList.Add(new Employee2SchedulerAppointmentDC { Employee = selectedEmployee }); } appointment.Originator = Model.LoggedInUser.Employee; } else { appointment.NewSchedulerAppointmentVersion = null; } KalenderService.InsertSchedulerAppointment(appointment); ViewData["EditableAppointmentModel"] = appointment; } foreach(var appointment in appointmentsToUpdate) { if(AppointmentModel.SelectedCustomers != null) { appointment.CustomerList = AppointmentModel.SelectedCustomers; } if(AppointmentModel.SelectedResources != null) { appointment.ResourceList = AppointmentModel.SelectedResources; } if(AppointmentModel.SelectedEmployees != null) { appointment.EmployeeList = new List(); foreach(var selectedEmployee in AppointmentModel.SelectedEmployees) { appointment.EmployeeList.Add(new Employee2SchedulerAppointmentDC { Employee = selectedEmployee }); } } appointment.ActivationType = ActivationTypeId.Active; KalenderService.UpdateSchedulerAppointments(new List { appointment }); } var oid2Version = appointmentsToRemove .Where(appointment => appointment.SchedulerAppointmentOid.HasValue && appointment.NewSchedulerAppointmentVersion.HasValue) .ToDictionary(k => k.SchedulerAppointmentOid.Value, v => v.NewSchedulerAppointmentVersion.Value); KalenderService.DeleteSchedulerAppointments(oid2Version); ReloadAppointments(); } [Authorize] public string SelectActiveViewType(string viewTypeName) { if(Enum.TryParse(viewTypeName, out var viewType)) { Model.CurrentViewType = viewType; UpdateUserSettingsWithoutReload(SettingsKeys.SchedulerViewType, ((int) viewType).ToString()); } return LeerzeichenFuerGetMethoden; } /// /// Hierüber laufen Custom-Aufrufe des DevExpress-Schedulers ab. Im JavaScript mit scheduler.PerformCallback(...) aufrufen. /// /// Etwaige Id des Termin-Objekts /// Die Id der auszuführenden Methode /// Etwaige Parameter für die auszuführende Methode /// Entweder das Scheduler-Partial oder einen anderen Seitenaufruf. [Authorize] public ActionResult CustomCallbackAction(string apptID, string actionId, string[] args) { switch(actionId) { case "ToServiceRecord": return ToServiceRecord(apptID, actionId, args); case "FilterAppointments": return FilterAppointments(args?.Length >= 1 ? args[0] : null); case "Reload": ReloadAppointments(); break; case "DeleteSeries": DeleteAppointment(((List) Model.Appointments).FirstOrDefault(appointment => appointment.SchedulerAppointmentOid == long.Parse(apptID))); break; case "DeleteApt": DeleteAppointment(((List) Model.Appointments).FirstOrDefault(appointment => appointment.SchedulerAppointmentOid == long.Parse(apptID))); break; case "ResetSeries": var oid2Versions = KalenderService.LoadOccurrencesByRecurrenceId(apptID).Where(appointment => appointment.RecurrenceIndexReference != null).ToDictionary(x => x.SchedulerAppointmentOid.Value, y => y.NewSchedulerAppointmentVersion.Value); KalenderService.DeleteSchedulerAppointments(oid2Versions); ReloadAppointments(); break; } return PartialView("SchedulerPagePartial", Model); } private void DeleteAppointment(SchedulerAppointmentDC appointment2Delete) { if(appointment2Delete is null || appointment2Delete.SchedulerAppointmentOid is null || appointment2Delete.NewSchedulerAppointmentVersion is null) { return; } var oid2Version = new Dictionary { { appointment2Delete.SchedulerAppointmentOid.Value, appointment2Delete.NewSchedulerAppointmentVersion.Value } }; KalenderService.DeleteSchedulerAppointments(oid2Version); ReloadAppointments(); } private void CreateDummyAppointments() { var today = DateTime.Today; var day1 = today; var day2 = day1.AddDays(1); switch(day2.DayOfWeek) { case DayOfWeek.Saturday: day2 = day1.AddDays(-2); // Samstag -> Donnerstag break; case DayOfWeek.Sunday: day2 = day1.AddDays(-3); // Sonntag -> Donnerstag break; } var day3 = day2.AddDays(1); switch(day3.DayOfWeek) { case DayOfWeek.Saturday: day3 = day2.AddDays(-2); // Samstag -> Donnerstag break; case DayOfWeek.Sunday: day3 = day2.AddDays(-3); // Sonntag -> Donnerstag break; } var employees = EmployeeService.GetAllCompactEmployees(); var customers = CustomerService.GetAllCompactCustomers(); var resources = KalenderService.GetAllResources(); var ich = Model.LoggedInCompactEmployee; var nichtIch = employees.First(employee => employee.EmployeeOid != ich.EmployeeOid); var weiterer = employees.First(employee => employee.EmployeeOid != ich.EmployeeOid && employee.EmployeeOid != nichtIch.EmployeeOid); var eigenerKlient = customers.FirstOrDefault(customer => ich.RelatedCustomerOIDList.Contains(customer.CustomerOid)); var fremderKlient = customers.FirstOrDefault(customer => ich.RelatedCustomerOIDList.Contains(customer.CustomerOid) is false); var ressource = resources.FirstOrDefault(); var ressource2 = resources.Count > 1 ? resources[1] : ressource; var nichtIchsKlient = customers.FirstOrDefault(customer => nichtIch.RelatedCustomerOIDList.Contains(customer.CustomerOid)); var nichtIchsFremderKlient = customers.FirstOrDefault(customer => nichtIch.RelatedCustomerOIDList.Contains(customer.CustomerOid) is false); // 1a) Einfacher eigener Termin var apt_1a = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(8,0,0), EndDate = day1.MergeDateWithHoursMinutesSeconds(9,0,0), Subject = "Einfacher eigener Termin", Location = "Datenbank", Originator = ich, Description = "Einfacher eigener Termin" }; // 1b) mit Mitarbeiter var apt_1b = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(9, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(10, 0, 0), Subject = "mit Mitarbeiter", Location = "Datenbank", Originator = ich, Description = "mit Mitarbeiter", EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } } }; // 1c) mit eigenem Klient var apt_1c = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(10, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(11, 0, 0), Subject = "mit eigenem Klient", Location = "Datenbank", Originator = ich, Description = "mit eigenem Klient", CustomerList = new List{ eigenerKlient } }; // 1d) mit fremdem Klient var apt_1d = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(11, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(12, 0, 0), Subject = "mit fremdem Klient", Location = "Datenbank", Originator = ich, Description = "mit fremdem Klient", CustomerList = new List{ fremderKlient } }; // 1e) mit Ressource var apt_1e = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(12, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(13, 0, 0), Subject = "mit Ressource", Location = "Datenbank", Originator = ich, Description = "mit Ressource", ResourceList = new List{ ressource } }; // 1f) mit Mitarbeiter, eigenem Klient var apt_1f = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(13, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(14, 0, 0), Subject = "mit Mitarbeiter, eigenem Klient", Location = "Datenbank", Originator = ich, Description = "mit Mitarbeiter, eigenem Klient", EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { eigenerKlient } }; // 1g) mit Mitarbeiter, fremdem Klient var apt_1g = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(14, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(15, 0, 0), Subject = "mit Mitarbeiter, fremdem Klient", Location = "Datenbank", Originator = ich, Description = "mit Mitarbeiter, fremdem Klient", EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { fremderKlient } }; // 1h) mit eigenem Klient, Ressource var apt_1h = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(15, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(16, 0, 0), Subject = "mit eigenem Klient, Ressource", Location = "Datenbank", Originator = ich, Description = "mit eigenem Klient, Ressource", CustomerList = new List { eigenerKlient }, ResourceList = new List { ressource } }; // 1i) mit fremdem Klient, Ressource var apt_1i = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(16, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(17, 0, 0), Subject = "mit fremdem Klient, Ressource", Location = "Datenbank", Originator = ich, Description = "mit fremdem Klient, Ressource", CustomerList = new List { fremderKlient }, ResourceList = new List { ressource } }; // 1j) mit Mitarbeiter, eigenem Klient, Ressource var apt_1j = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(17, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(18, 0, 0), Subject = "mit Mitarbeiter, eigenem Klient, Ressource", Location = "Datenbank", Originator = ich, Description = "mit Mitarbeiter, eigenem Klient, Ressource", EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { eigenerKlient }, ResourceList = new List { ressource } }; // 1k) mit Mitarbeiter, fremdem Klient, Ressource var apt_1k = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(18, 0, 0), EndDate = day1.MergeDateWithHoursMinutesSeconds(19, 0, 0), Subject = "mit Mitarbeiter, fremdem Klient, Ressource", Location = "Datenbank", Originator = ich, Description = "mit Mitarbeiter, fremdem Klient, Ressource", EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { fremderKlient }, ResourceList = new List { ressource } }; // ----------------------------------------------------------------------------- // 2a) einfach var apt_2a = new SchedulerAppointmentDC { StartDate = day1.MergeDateWithHoursMinutesSeconds(19), EndDate = day1.MergeDateWithHoursMinutesSeconds(20), Subject = "einfach", Location = "Datenbank", Originator = nichtIch, Description = "einfach" }; // 2b) mit Mitarbeiter var apt_2b = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(8), EndDate = day2.MergeDateWithHoursMinutesSeconds(9), Subject = "mit Mitarbeiter", Location = "Datenbank", Description = "mit Mitarbeiter", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = weiterer } } }; // 2c) mit angemeldetem Mitarbeiter var apt_2c = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(9), EndDate = day2.MergeDateWithHoursMinutesSeconds(10), Subject = "mit angemeldetem Mitarbeiter", Location = "Datenbank", Description = "mit angemeldetem Mitarbeiter", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } } }; // 2d) mit eigenem Klient var apt_2d = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(10), EndDate = day2.MergeDateWithHoursMinutesSeconds(11), Subject = "mit eigenem Klient", Location = "Datenbank", Description = "mit eigenem Klient", Originator = nichtIch, CustomerList = new List { nichtIchsKlient } }; // 2e) mit fremdem Klient var apt_2e = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(11), EndDate = day2.MergeDateWithHoursMinutesSeconds(12), Subject = "mit fremdem Klient", Location = "Datenbank", Description = "mit fremdem Klient", Originator = nichtIch, CustomerList = new List { nichtIchsFremderKlient } }; // 2f) mit Ressource var apt_2f = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(12), EndDate = day2.MergeDateWithHoursMinutesSeconds(13), Subject = "mit Ressource", Location = "Datenbank", Description = "mit Ressource", Originator = nichtIch, ResourceList = new List{ ressource2 } }; // 2g) mit Mitarbeiter, eigenem Klient var apt_2g = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(13), EndDate = day2.MergeDateWithHoursMinutesSeconds(14), Subject = "mit Mitarbeiter, eigenem Klient", Location = "Datenbank", Description = "mit Mitarbeiter, eigenem Klient", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = weiterer } }, CustomerList = new List { nichtIchsKlient } }; // 2h) mit Mitarbeiter, fremdem Klient var apt_2h = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(14), EndDate = day2.MergeDateWithHoursMinutesSeconds(15), Subject = "mit Mitarbeiter, fremdem Klient", Location = "Datenbank", Description = "mit Mitarbeiter, fremdem Klient", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = weiterer } }, CustomerList = new List { nichtIchsFremderKlient } }; // 2i) mit eigenem Klient, Ressource var apt_2i = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(15), EndDate = day2.MergeDateWithHoursMinutesSeconds(16), Subject = "mit eigenem Klient, Ressource", Location = "Datenbank", Description = "mit eigenem Klient, Ressource", Originator = nichtIch, CustomerList = new List{ nichtIchsKlient }, ResourceList = new List{ ressource2 } }; // 2j) mit fremdem Klient, Ressource var apt_2j = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(16), EndDate = day2.MergeDateWithHoursMinutesSeconds(17), Subject = "mit fremdem Klient, Ressource", Location = "Datenbank", Description = "mit fremdem Klient, Ressource", Originator = nichtIch, CustomerList = new List { nichtIchsFremderKlient }, ResourceList = new List { ressource2 } }; // 2k) mit Mitarbeiter, eigenem Klient, Ressource var apt_2k = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(17), EndDate = day2.MergeDateWithHoursMinutesSeconds(18), Subject = "mit Mitarbeiter, eigenem Klient, Ressource", Location = "Datenbank", Description = "mit Mitarbeiter, eigenem Klient, Ressource", Originator = nichtIch }; // 2l) mit Mitarbeiter, fremdem Klient, Ressource var apt_2l = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(18), EndDate = day2.MergeDateWithHoursMinutesSeconds(19), Subject = "mit Mitarbeiter, fremdem Klient, Ressource", Location = "Datenbank", Description = "mit Mitarbeiter, fremdem Klient, Ressource", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = weiterer } }, CustomerList = new List { nichtIchsFremderKlient }, ResourceList = new List { ressource2 } }; // 2m) mit angemeldetem Mitarbeiter, dessen Klient var apt_2m = new SchedulerAppointmentDC { StartDate = day2.MergeDateWithHoursMinutesSeconds(19), EndDate = day2.MergeDateWithHoursMinutesSeconds(20), Subject = "mit angemeldetem Mitarbeiter, dessen Klient", Location = "Datenbank", Description = "mit angemeldetem Mitarbeiter, dessen Klient", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { eigenerKlient } }; // 2n) mit angemeldetem Mitarbeiter, diesem fremdem Klient var apt_2n = new SchedulerAppointmentDC { StartDate = day3.MergeDateWithHoursMinutesSeconds(8), EndDate = day3.MergeDateWithHoursMinutesSeconds(9), Subject = "mit angemeldetem Mitarbeiter, diesem fremdem Klient", Location = "Datenbank", Description = "mit angemeldetem Mitarbeiter, diesem fremdem Klient", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { fremderKlient } }; // 2o) mit angemeldetem Mitarbeiter, dessen Klient, Ressource var apt_2o = new SchedulerAppointmentDC { StartDate = day3.MergeDateWithHoursMinutesSeconds(9), EndDate = day3.MergeDateWithHoursMinutesSeconds(10), Subject = "mit angemeldetem Mitarbeiter, dessen Klient, Ressource", Location = "Datenbank", Description = "mit angemeldetem Mitarbeiter, dessen Klient, Ressource", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { eigenerKlient }, ResourceList = new List{ ressource } }; // 2p) mit angemeldetem Mitarbeiter, diesem fremdem Klient, Ressource var apt_2p = new SchedulerAppointmentDC { StartDate = day3.MergeDateWithHoursMinutesSeconds(10), EndDate = day3.MergeDateWithHoursMinutesSeconds(11), Subject = "mit angemeldetem Mitarbeiter, diesem fremdem Klient, Ressource", Location = "Datenbank", Description = "mit angemeldetem Mitarbeiter, diesem fremdem Klient, Ressource", Originator = nichtIch, EmployeeList = new List { new Employee2SchedulerAppointmentDC { Employee = nichtIch }, new Employee2SchedulerAppointmentDC { Employee = ich } }, CustomerList = new List { fremderKlient }, ResourceList = new List { ressource } }; var appointmentsToInsert = new List { apt_1a, apt_1b, apt_1c, apt_1d, apt_1e, apt_1f, apt_1g, apt_1h, apt_1i, apt_1j, apt_1k, apt_2a, apt_2b, apt_2c, apt_2d, apt_2e, apt_2f, apt_2g, apt_2h, apt_2i, apt_2j, apt_2k, apt_2l, apt_2m, apt_2n, apt_2o, apt_2p }; foreach(var appointment in appointmentsToInsert) { appointment.ActivationType = ActivationTypeId.Active; } KalenderService.InsertSchedulerAppointments(appointmentsToInsert); ReloadAppointments(); } [Authorize] private ActionResult ToServiceRecord(string apptID, string actionId, string[] args) { long? selectedAppointmentOid; var isRecurring = false; // Serientermin if(apptID.Contains("_")) { var splitApptId = apptID.Split('_'); selectedAppointmentOid = long.Parse(splitApptId[0]); var recurrenceIndex = int.Parse(splitApptId[1]); TempData[TempDataConstants.AppointmentRecurrenceIndexKey] = recurrenceIndex; } else { selectedAppointmentOid = long.Parse(apptID); } var appointment = selectedAppointmentOid.HasValue ? Model.GetAppointmentByOid(selectedAppointmentOid.Value) : null; TempData[TempDataConstants.AppointmentOidKey] = appointment?.SchedulerAppointmentOid; TempData[TempDataConstants.AppointmentStartKey] = appointment?.StartDate; TempData[TempDataConstants.AppointmentEndKey] = appointment?.EndDate; TempData[TempDataConstants.AppointmentSubjectKey] = appointment?.Subject; TempData[TempDataConstants.AppointmentIsAllDayKey] = appointment?.AllDay ?? false; TempData[TempDataConstants.AppointmentCustomerOidsKey] = string.Join(",", appointment?.CustomerList.Select(s => s.CustomerOid) ?? new List()); TempData[TempDataConstants.AppointmentEmployeeOidsKey] = string.Join(",", appointment?.EmployeeList.Select(s => s.Employee.EmployeeOid) ?? new List()); TempData[TempDataConstants.AppointmentIsSerienterminKey] = appointment != null && selectedAppointmentOid is null && appointment.RecurrenceInfo is string; return RedirectToActionPermanent("PrepareServiceRecordInsert", "Main"); } [Authorize] public string GetAppointmentType(long oid) { var appointment = Model.GetAppointmentByOid(oid); var showMenuItem = false; var isTask = appointment.IsTask; var isAbsenceTime = appointment.AbsenceReason != null; if(isTask) { //showMenuItem = } return JsonConvert.SerializeObject(showMenuItem); } private void UpdateSelectedObjects() { var list = new List(); Model.ResourceCategories2Resources.Values.DoForEach(l => l.DoForEach(s => list.AddIfNotIn(s))); //Model.SelectedEmployees = Model.PossibleEmployees.Where(employee => Model.SelectedEmployeeOids.Contains(employee.EmployeeOid)).ToList(); //Model.SelectedCustomers = Model.PossibleCustomers.Where(customer => Model.SelectedCustomerOids.Contains(customer.CustomerOid)).ToList(); //Model.SelectedResources = list.Where(resource => resource.ResourceOid.HasValue && Model.SelectedResourceOids.Contains(resource.ResourceOid.Value)).ToList(); AppointmentModel.SelectedEmployees = Model.PossibleEmployees.Where(employee => Model.SelectedEmployeeOids.Contains(employee.EmployeeOid)).ToList(); AppointmentModel.SelectedCustomers = Model.PossibleCustomers.Where(customer => Model.SelectedCustomerOids.Contains(customer.CustomerOid)).ToList(); AppointmentModel.SelectedResources = list.Where(resource => resource.ResourceOid.HasValue && Model.SelectedResourceOids.Contains(resource.ResourceOid.Value)).ToList(); Model.SelectedEmployeesForFiltering = Model.PossibleEmployees.Where(employee => Model.SelectedEmployeeOidsForFiltering.Contains(employee.EmployeeOid)).ToList(); Model.SelectedCustomersForFiltering = Model.PossibleCustomers.Where(customer => Model.SelectedCustomerOidsForFiltering.Contains(customer.CustomerOid)).ToList(); Model.SelectedResourcesForFiltering = list.Where(resource => resource.ResourceOid.HasValue && Model.SelectedResourceOidsForFiltering.Contains(resource.ResourceOid.Value)).ToList(); } [Authorize] public ActionResult CheckEmployeeAvailability(string startString, string endString) { var start = DateTime.Parse(startString); var end = DateTime.Parse(endString); var availabilities = ReportService.GetMitarbeiterverfuegbarkeiten(AppointmentModel.PossibleEmployees, start, end); var employee2Overtime = new EmployeeAvailabilityObject(start, end, availabilities); Model.EmployeeAvailabilityObject = employee2Overtime; ViewData[ViewDataConstants.SchedulerEmployeeAvailabilityConstant] = employee2Overtime; return PartialView("SchedulerPagePartial", Model); } [Authorize] public ActionResult SelectAllEmployeesForFiltering(bool isChecked) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltEmployeePopupListPartial"); } if(isChecked) { Model.SelectedEmployeesForFiltering = Model.PossibleEmployees; Model.SelectedEmployeeOidsForFiltering = Model.PossibleEmployees.Select(employee => employee.EmployeeOid).ToList(); } else { Model.SelectedEmployeesForFiltering?.Clear(); Model.SelectedEmployeeOidsForFiltering?.Clear(); } return PartialView("AptFltEmployeePopupListPartial", Model); } [Authorize] public ActionResult SelectAllCustomersForFiltering(bool isChecked) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltCustomerPopupListPartial"); } if(isChecked) { Model.SelectedCustomerOidsForFiltering = Model.PossibleCustomers.Select(customer => customer.CustomerOid).ToList(); Model.SelectedCustomersForFiltering = Model.PossibleCustomers; } else { Model.SelectedCustomerOidsForFiltering?.Clear(); Model.SelectedCustomersForFiltering?.Clear(); } return PartialView("AptFltCustomerPopupListPartial", Model); } [Authorize] public ActionResult SelectAllResourcesForFiltering(bool isChecked) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltResourcePopupListPartial"); } if(isChecked) { Model.SelectedResourceOidsForFiltering = Model.PossibleResources.Where(resource => resource.ResourceOid.HasValue).Select(resource => resource.ResourceOid.Value).ToList(); Model.SelectedResourcesForFiltering = Model.PossibleResources; } else { Model.SelectedResourceOidsForFiltering?.Clear(); Model.SelectedResourcesForFiltering?.Clear(); } return PartialView("AptFltResourcePopupListPartial", Model); } [Authorize] public ActionResult SelectTeamForAppointment(long teamOid) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltEmployeePopupListPartial"); } var selectedTeam = Model.MyTeams.FirstOrDefault(team => team.TeamOid.Equals(teamOid)); if(selectedTeam is null) { return PartialView("AptFltEmployeePopupListPartial", Model); } var fullTeamObj = EmployeeService.LoadTeam(teamOid); var teamMembers = fullTeamObj?.Member ?? new List(); Model.SelectedEmployeesForFiltering.AddRangeIfElementsNotIn(teamMembers); Model.SelectedEmployeeOids.AddRangeIfElementsNotIn(teamMembers.Select(member => member.EmployeeOid)); return PartialView("AptFltEmployeePopupListPartial", Model); } [Authorize] public ActionResult UpdateEmployeeFilterSelection(long[] selectedOids) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltEmployeePopupListPartial"); } if(selectedOids is null) { selectedOids = Array.Empty(); } var selectedEmployees = Model.PossibleEmployees.Where(possibleEmployee => selectedOids.Contains(possibleEmployee.EmployeeOid)).ToList(); Model.SelectedEmployeesForFiltering = selectedEmployees; Model.SelectedEmployeeOidsForFiltering = selectedEmployees.Select(employee => employee.EmployeeOid).ToList(); return PartialView("AptFltEmployeePopupListPartial", Model); } [Authorize] public ActionResult UpdateCustomerFilterSelection(long[] selectedOids) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltCustomerPopupListPartial"); } if(selectedOids is null) { selectedOids = Array.Empty(); } var selectedCustomers = Model.PossibleCustomers.Where(possibleCustomer => selectedOids.Contains(possibleCustomer.CustomerOid)).ToList(); Model.SelectedCustomersForFiltering = selectedCustomers; Model.SelectedCustomerOidsForFiltering = selectedCustomers.Select(customer => customer.CustomerOid).ToList(); return PartialView("AptFltCustomerPopupListPartial", Model); } [Authorize] public ActionResult UpdateResourceFilterSelection(long[] selectedOids) { if(Model is null) { TempData[TempDataConstants.DoLogoutKey] = true; return PartialView("AptFltResourcePopupListPartial"); } if(selectedOids is null) { selectedOids = Array.Empty(); } var selectedResources = Model.PossibleResources.Where(possibleResource => possibleResource.ResourceOid.HasValue && selectedOids.Contains(possibleResource.ResourceOid.Value)).ToList(); Model.SelectedResourcesForFiltering = selectedResources; Model.SelectedResourceOidsForFiltering = selectedResources.Where(resource => resource.ResourceOid.HasValue).Select(resource => resource.ResourceOid.Value).ToList(); return PartialView("AptFltResourcePopupListPartial", Model); } [Authorize] public string GetSelectedEmployeesForAptFlt() { return JsonConvert.SerializeObject(Model.SelectedEmployeeOidsForFiltering.Count); } [Authorize] public string GetSelectedCustomersForAptFlt() { return JsonConvert.SerializeObject(Model.SelectedCustomerOidsForFiltering.Count); } [Authorize] public string GetSelectedResourcesForAptFlt() { return JsonConvert.SerializeObject(Model.SelectedResourceOidsForFiltering.Count); } private ActionResult FilterAppointments(string filters) { var filterPairs = filters?.Split(';') ?? Array.Empty(); foreach(var pair in filterPairs) { var id2Checked = pair.Split("_"); var isChecked = id2Checked[1] == "on"; var id = id2Checked[0]; switch(id) { case "only-my-own-appointments-cb2": Model.ShowOnlyMyOwnAppointments = isChecked; UpdateUserSettingsWithoutReload(SettingsKeys.ZeigeNurMeineTermine, isChecked.ToString()); break; case "only-private-appointments-cb2": Model.ShowOnlyPrivateAppointments = isChecked; break; case "employee-colors-cb2": Model.ShowEmployeeColors = isChecked; break; case "absence-times-cb2": Model.ShowAbsenceTimes = isChecked; break; case "tasks-cb2": Model.ShowTasks = isChecked; break; case "only-employees-cb2": Model.ShowOnlyEmployees = isChecked; break; case "only-customers-cb2": Model.ShowOnlyCustomers = isChecked; break; case "only-resources-cb2": Model.ShowOnlyResources = isChecked; break; } } ReloadAppointments(); return PartialView("SchedulerPagePartial", Model); } [Authorize] public string UnselectAppointment2Answer() { Model.AppointmentOidToAnswerOrUpdate = null; Model.AppointmentToAnswerOrUpdate = null; return LeerzeichenFuerGetMethoden; } [Authorize] public ActionResult LoadAppointmentToAnswer(long oid) { var relation = Model.OpenEmployee2AppointmentRels.FirstOrDefault(f => f.Employee2SchedulerAppointmentOid.HasValue && f.Employee2SchedulerAppointmentOid.Equals(oid)); if(relation != null) { Model.Employee2AppointmentToAnswerOrUpdateRel = relation; Model.Employee2AppointmentToAnswerOrUpdateRelOid = relation.Employee2SchedulerAppointmentOid; var appointment = Model.OpenAppointments.FirstOrDefault(f => f.EmployeeList.Any(a => a.Employee2SchedulerAppointmentOid.Equals(relation.Employee2SchedulerAppointmentOid.Value))); if(appointment != null) { Model.AppointmentToAnswerOrUpdate = appointment; Model.AppointmentOidToAnswerOrUpdate = appointment.SchedulerAppointmentOid; } } return PartialView("SelectedOpenEmployee2AppointmentFormPartial", Model); } [Authorize] public ActionResult AnswerOpenAppointment(int answer) { var appointmentOid = Model.AppointmentOidToAnswerOrUpdate; var relationOid = Model.Employee2AppointmentToAnswerOrUpdateRelOid; var appointment = Model.OpenAppointments.FirstOrDefault(f => f.SchedulerAppointmentOid.Equals(appointmentOid)); var relation = Model.OpenEmployee2AppointmentRels.FirstOrDefault(f => f.Employee2SchedulerAppointmentOid.Equals(relationOid)); if(relation is null) { throw new ArgumentNullException(nameof(relation), "Das Employee2NewSchedulerAppointmentDC-Objekt ist in der Funktion 'AnswerOpenAppointment' wider Erwarten null!"); } if(appointment is null) { throw new ArgumentNullException(nameof(appointment), "Das SchedulerAppointmentDC-Objekt ist in der Funktion 'AnswerOpenAppointment' wider Erwarten null!"); } if(answer == 5) { relation.IsPC_CheckedTs = DateTime.Now; } else { var participationAnswer = (ParticipationAnswer) answer; relation.ParticipationAnswer = participationAnswer; relation.IsPChanged = true; } KalenderService.UpdateEmployee2SchedulerAppointments(new List { relation }); Model.AppointmentOidToAnswerOrUpdate = null; Model.Employee2AppointmentToAnswerOrUpdateRelOid = null; ReloadAppointments(); return PartialView("NotificationsPopupContent", Model); } [Authorize] public ActionResult ReloadOpenAppointments() { ReloadAppointments(); return PartialView("OpenEmployee2AppointmentListPartial", Model); } [Authorize] public ActionResult ConfirmAllOpenAppointments() { var rels = Model.OpenEmployee2AppointmentRels; var appointmentOids = rels .Where(employee2Appointment => employee2Appointment.SchedulerAppointmentOid.HasValue) .Select(employee2Appointment => employee2Appointment.SchedulerAppointmentOid.Value) .ToList(); var appointments = Model.OpenAppointments.Where(appointment => appointment.SchedulerAppointmentOid.HasValue && appointmentOids.Contains(appointment.SchedulerAppointmentOid.Value)).ToList(); foreach(var appointment in appointments) { foreach(var employee2Appointment in appointment.EmployeeList) { if(employee2Appointment.Employee.Equals(Model.LoggedInCompactEmployee)) { employee2Appointment.IsPChanged = true; employee2Appointment.ParticipationAnswer = ParticipationAnswer.Zusage; } } } KalenderService.UpdateSchedulerAppointments(appointments); ReloadAppointments(); return PartialView("NotificationsPopupContent", Model); } [Authorize] public string GetOpenEmp2AppRelCount() { return JsonConvert.SerializeObject(Model.OpenEmployee2AppointmentRelOids.Count); } [Authorize] public ActionResult UpdateOpenEmp2AppCount() { return PartialView("NotificationsLinkPartial", Model); } [Authorize] public ActionResult RightClickConfirm(int answer, long id) { var appointments = (List) Model.Appointments; var appointment2Answer = appointments.FirstOrDefault(appointment => appointment.SchedulerAppointmentOid?.Equals(id) ?? false); var rel = appointment2Answer?.EmployeeList.FirstOrDefault(employee2Appointment => employee2Appointment.Employee.Equals(Model.LoggedInCompactEmployee)); if(rel != null) { rel.ParticipationAnswer = (ParticipationAnswer) answer; rel.IsPChanged = true; rel.IsPC_CheckedTs = DateTime.Now; } KalenderService.UpdateSchedulerAppointments(new List { appointment2Answer }); ReloadAppointments(); return PartialView("SchedulerPagePartial", Model); } [Authorize] public string GetEmployeePageCount() { return JsonConvert.SerializeObject(new EditFormInfo(AppointmentModel.EmployeePageCount, AppointmentModel.EmployeePageLimit)); } [Authorize] public string GetCustomerPageCount() { return JsonConvert.SerializeObject(new EditFormInfo(AppointmentModel.CustomerPageCount, AppointmentModel.CustomerPageLimit)); } [Authorize] public string GetResourcePageCount() { return JsonConvert.SerializeObject(new EditFormInfo(AppointmentModel.ResourcePageCount, AppointmentModel.ResourcePageLimit)); } [Authorize] public string UpdateAppointmentEmployeeSelection(string selectedOids) { if(selectedOids is null) { selectedOids = string.Empty; } var selectedEmployeeOids = selectedOids.Length == 0 ? new List() : selectedOids.Split(',').Select(long.Parse).ToList(); var relationsToKeep = AppointmentModel.SelectedEmployee2SchedulerAppointments?.Where(e2A => selectedEmployeeOids.Contains(e2A.Employee.EmployeeOid)).ToList() ?? new List(); var newlySelectedEmployeeOids = selectedEmployeeOids.Except(relationsToKeep.Select(e2A => e2A.Employee.EmployeeOid)); AppointmentModel.SelectedEmployee2SchedulerAppointments = new List(relationsToKeep); var oids = AppointmentModel.PossibleEmployees.Where(e => selectedEmployeeOids.Contains(e.EmployeeOid)).Select(e => e.EmployeeOid).ToList(); var employees = AppointmentModel.PossibleEmployees.Where(possibleEmployee => newlySelectedEmployeeOids.Contains(possibleEmployee.EmployeeOid)).ToList(); foreach(var employee in employees) { AppointmentModel.SelectedEmployee2SchedulerAppointments.Add(new Employee2SchedulerAppointmentDC { Employee = employee }); } AppointmentModel.SelectedEmployeeOids = oids; return JsonConvert.SerializeObject(AppointmentModel.SelectedEmployee2SchedulerAppointments?.Count ?? 0); } [Authorize] public string UpdateAppointmentCustomerSelection(string selectedOids) { if(selectedOids is null) { selectedOids = string.Empty; } AppointmentModel.SelectedCustomerOids = selectedOids.Length == 0 ? new List() : selectedOids.Split(',').Select(long.Parse).ToList(); return JsonConvert.SerializeObject(AppointmentModel.SelectedCustomerOids?.Count ?? 0); } [Authorize] public string UpdateAppointmentResourceSelection(string selectedOids) { if(selectedOids is null) { selectedOids = string.Empty; } AppointmentModel.SelectedResourceOids = selectedOids.Length == 0 ? new List() : selectedOids.Split(',').Select(long.Parse).ToList(); return JsonConvert.SerializeObject(AppointmentModel.SelectedResourceOids?.Count ?? 0); } } public class EditFormInfo { public int PageCount { get; } public int PageLimit { get; } public EditFormInfo(int pageCount, int pageLimit) { PageCount = pageCount; PageLimit = pageLimit; } } }