943 lines
38 KiB
C#
943 lines
38 KiB
C#
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;
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
{
|
|
/*
|
|
* ToDo:
|
|
* 1. Filterung einbauen (Mitarbeiter, Klienten, Ressourcen, Privat, Aufgaben, Abwesenheiten)
|
|
* 2. Benachrichtigungen einbauen
|
|
* 3. Rechte implementieren
|
|
* 4. Ü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<ValueListEntryDC, List<ResourceDC>>();
|
|
|
|
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<long> { employeeOid };
|
|
}
|
|
|
|
Model.PossibleEmployees = EmployeeService.GetAllAuthorizedCompactEmployees();
|
|
Model.PossibleCustomers = CustomerService.GetAllAuthorizedCompactCustomers();
|
|
Model.PossibleResources = KalenderService.GetAllResources();
|
|
|
|
if(Model.HasRightToInsertRessourceAppointments || Model.HasRightToViewAllResourceAppointments)
|
|
{
|
|
var allResources = KalenderService.GetAllResources().OrderBy(r => r.Name).ToList();
|
|
|
|
var categories2Resources = new Dictionary<ValueListEntryDC, List<ResourceDC>>();
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
Model.CurrentViewType = (SchedulerViewType) UserSettingsUtils.GetSettingValueAsInteger(userSettings, SettingsKeys.SchedulerViewType);
|
|
|
|
var intervalStart = DateTimeExtensions.GetDayOfWeek(DayOfWeek.Monday);
|
|
var intervalEnd = intervalStart.AddDays(7);
|
|
|
|
var appointments = KalenderService.LoadFilteredAppointmentsMitAufgaben
|
|
(
|
|
Model.HasRightKalenderMitarbeitertermineAnsehen,
|
|
employeeOid,
|
|
intervalStart,
|
|
intervalEnd,
|
|
Model.SelectedEmployeeOidsForFiltering,
|
|
Model.SelectedCustomerOidsForFiltering,
|
|
Model.SelectedResourceOidsForFiltering,
|
|
Model.ShowOnlyEmployees,
|
|
Model.ShowOnlyCustomers,
|
|
Model.ShowOnlyResources,
|
|
Model.ShowOnlyPrivateAppointments,
|
|
Model.ShowOnlyMyOwnAppointments,
|
|
Model.ShowTasks
|
|
);
|
|
|
|
var allCustomerOids = Model.PossibleCustomers.Select(s => s.CustomerOid).ToList();
|
|
var allEmployeeOids = Model.PossibleEmployees.Select(s => s.EmployeeOid).ToList();
|
|
|
|
var customerAbsenceTimes = KalenderService.GetAllActiveCustomersAbsenceTimesInInterval(intervalStart, intervalEnd, employeeOid, allCustomerOids);
|
|
var employeeAbsenceTimes = KalenderService.GetAllActiveEmployeeAbsenceTimesInInterval(intervalStart, intervalEnd, employeeOid, allEmployeeOids);
|
|
|
|
if(Model.ShowAbsenceTimes)
|
|
{
|
|
var allAbsenceTimes = new List<AbsenceTimeDC>();
|
|
allAbsenceTimes.AddRange(customerAbsenceTimes);
|
|
allAbsenceTimes.AddRange(employeeAbsenceTimes);
|
|
|
|
appointments.AddRange(ConvertAbsenceTimesToAppointments(allAbsenceTimes, Model.PossibleCustomers, Model.PossibleEmployees));
|
|
}
|
|
|
|
Model.Appointments = appointments;
|
|
|
|
LoadNotificationCount();
|
|
}
|
|
|
|
[Authorize]
|
|
public ActionResult GetNotifications()
|
|
{
|
|
LoadNotificationCount();
|
|
|
|
return PartialView("SchedulerNotificationPartial", Model);
|
|
}
|
|
|
|
private void LoadNotificationCount()
|
|
{
|
|
Model.OpenAppointments = KalenderService.GetAllOpenAppointmentsForEmployee(LoggedInUser.Employee.EmployeeOid).OrderByDescending(openAppointment => openAppointment.StartDate).ToList();
|
|
Model.OpenAppointmentOids = Model.OpenAppointments.Where(openAppointment => openAppointment.SchedulerAppointmentOid.HasValue).Select(openAppointment => openAppointment.SchedulerAppointmentOid.Value).ToList();
|
|
|
|
if(Model.AppointmentOid2Answer.HasValue)
|
|
{
|
|
Model.Appointment2Answer = Model.OpenAppointments.FirstOrDefault(openAppointment => openAppointment.SchedulerAppointmentOid?.Equals(Model.AppointmentOid2Answer.Value) ?? false);
|
|
}
|
|
else
|
|
{
|
|
var first = Model.OpenAppointments.FirstOrDefault();
|
|
|
|
if(first != null)
|
|
{
|
|
Model.Appointment2Answer = first;
|
|
Model.AppointmentOid2Answer = first.SchedulerAppointmentOid;
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<SchedulerAppointmentDC> ConvertAbsenceTimesToAppointments(List<AbsenceTimeDC> absenceTimes, List<CompactCustomerDC> allCustomers, List<CompactEmployeeDC> allEmployees)
|
|
{
|
|
var appointments = new List<SchedulerAppointmentDC>();
|
|
|
|
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<CompactCustomerDC> { 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<object>();
|
|
|
|
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<SchedulerAppointmentDC>(
|
|
"scheduler",
|
|
Model.Appointments,
|
|
SchedulerHelper.DefaultAppointmentStorage,
|
|
SchedulerHelper.DefaultResourceStorage);
|
|
|
|
var appointmentsToUpdate = SchedulerExtension.GetAppointmentsToUpdate<SchedulerAppointmentDC>(
|
|
"scheduler",
|
|
Model.Appointments,
|
|
SchedulerHelper.DefaultAppointmentStorage,
|
|
SchedulerHelper.DefaultResourceStorage
|
|
);
|
|
|
|
var appointmentsToRemove = SchedulerExtension.GetAppointmentsToRemove<SchedulerAppointmentDC>(
|
|
"scheduler",
|
|
Model.Appointments,
|
|
SchedulerHelper.DefaultAppointmentStorage,
|
|
SchedulerHelper.DefaultResourceStorage
|
|
);
|
|
|
|
foreach(var appointment in appointmentsToInsert)
|
|
{
|
|
appointment.CustomerList = AppointmentModel.SelectedCustomers;
|
|
appointment.ResourceList = AppointmentModel.SelectedResources;
|
|
appointment.EmployeeList = AppointmentModel.SelectedEmployee2SchedulerAppointments;
|
|
|
|
appointment.Originator = Model.LoggedInUser.Employee;
|
|
|
|
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<Employee2SchedulerAppointmentDC>();
|
|
|
|
foreach(var selectedEmployee in AppointmentModel.SelectedEmployees)
|
|
{
|
|
appointment.EmployeeList.Add(new Employee2SchedulerAppointmentDC { Employee = selectedEmployee });
|
|
}
|
|
}
|
|
|
|
appointment.ActivationType = ActivationTypeId.Active;
|
|
|
|
KalenderService.UpdateSchedulerAppointments(new List<SchedulerAppointmentDC> { appointment });
|
|
}
|
|
|
|
KalenderService.DeleteSchedulerAppointments(
|
|
appointmentsToRemove
|
|
.Where(appointment => appointment.SchedulerAppointmentOid.HasValue && appointment.NewSchedulerAppointmentVersion.HasValue)
|
|
.ToDictionary(k => k.SchedulerAppointmentOid.Value, v => v.NewSchedulerAppointmentVersion.Value));
|
|
|
|
ReloadAppointments();
|
|
}
|
|
|
|
//[HttpPost]
|
|
//public ActionResult CustomerMultiSelectPartial(string value)
|
|
//{
|
|
// var selectedCustomerOids = GridLookupExtension.GetSelectedValues<long?>("CustomerGridLookup") ?? Array.Empty<long?>();
|
|
|
|
// AppointmentModel.SelectedCustomerOids = selectedCustomerOids.Where(oid => oid.HasValue).Select(oid => oid.Value).ToList();
|
|
|
|
// return PartialView("CustomerMultiSelectPartial", AppointmentModel);
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public ActionResult ResourceGridLookupPartial(string value)
|
|
//{
|
|
// var selectedResourceOids = GridLookupExtension.GetSelectedValues<long?>("ResourceGridLookup") ?? Array.Empty<long?>();
|
|
|
|
// AppointmentModel.SelectedResourceOids = selectedResourceOids.Where(oid => oid.HasValue).Select(oid => oid.Value).ToList();
|
|
|
|
// return PartialView("ResourceMultiSelectPartial", AppointmentModel);
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public ActionResult EmployeeGridLookupPartial(string value)
|
|
//{
|
|
// /*
|
|
// * Im AppointmentModel müssen die PossibleEmployees bleiben, denn daraus wählt man die Mitarbeiter, die noch nicht mit dem Termin
|
|
// * verknüpft sind und es müssen - zumindest beim Bearbeiten - die bereits mit dem Termin verbundenen Mitarbeiter-zu-Termin-Relationen
|
|
// * zwischengespeichert werden.
|
|
// *
|
|
// */
|
|
// var selectedEmployeeOids = GridLookupExtension.GetSelectedValues<long?>("EmployeeGridLookup") ?? Array.Empty<long?>();
|
|
|
|
// AppointmentModel.SelectedEmployeeOids = selectedEmployeeOids.Where(oid => oid.HasValue).Select(oid => oid.Value).ToList();
|
|
|
|
// return PartialView("EmployeeMultiSelectPartial", AppointmentModel);
|
|
//}
|
|
|
|
[Authorize]
|
|
public string SelectActiveViewType(string viewTypeName)
|
|
{
|
|
if(Enum.TryParse<SchedulerViewType>(viewTypeName, out var viewType))
|
|
{
|
|
Model.CurrentViewType = viewType;
|
|
|
|
UpdateUserSettingsWithoutReload(SettingsKeys.SchedulerViewType, ((int) viewType).ToString());
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hierüber laufen Custom-Aufrufe des DevExpress-Schedulers ab. Im JavaScript mit scheduler.PerformCallback(...) aufrufen.
|
|
/// </summary>
|
|
/// <param name="apptID">Etwaige Id des Termin-Objekts</param>
|
|
/// <param name="actionId">Die Id der auszuführenden Methode</param>
|
|
/// <param name="args">Etwaige Parameter für die auszuführende Methode</param>
|
|
/// <returns>Entweder das Scheduler-Partial oder einen anderen Seitenaufruf.</returns>
|
|
[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;
|
|
}
|
|
|
|
return PartialView("SchedulerPagePartial", Model);
|
|
}
|
|
|
|
[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<long>());
|
|
|
|
TempData[TempDataConstants.AppointmentEmployeeOidsKey] = string.Join(",", appointment?.EmployeeList.Select(s => s.Employee.EmployeeOid) ?? new List<long>());
|
|
|
|
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<ResourceDC>();
|
|
|
|
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();
|
|
|
|
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<CompactEmployeeDC>();
|
|
|
|
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<long>();
|
|
}
|
|
|
|
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<long>();
|
|
}
|
|
|
|
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<long>();
|
|
}
|
|
|
|
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<string>();
|
|
|
|
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 ActionResult LoadAppointmentToAnswer(long oid)
|
|
{
|
|
Model.Appointment2Answer = Model.OpenAppointments.FirstOrDefault(openAppointment => openAppointment.SchedulerAppointmentOid?.Equals(oid) ?? false);
|
|
|
|
return PartialView("NotificationPopupContent", Model);
|
|
}
|
|
|
|
[Authorize]
|
|
public ActionResult AnswerOpenAppointment(int answer)
|
|
{
|
|
var appointment = Model.Appointment2Answer;
|
|
|
|
var employeeRelation = appointment.EmployeeList.FirstOrDefault(employee2Appointment => employee2Appointment.Employee.EmployeeOid == Model.LoggedInUser.Employee.EmployeeOid);
|
|
|
|
if(employeeRelation != null)
|
|
{
|
|
employeeRelation.ParticipationAnswer = (ParticipationAnswer) answer;
|
|
employeeRelation.IsPChanged = true;
|
|
employeeRelation.IsPC_CheckedTs = DateTime.Now;
|
|
}
|
|
|
|
KalenderService.UpdateSchedulerAppointments(new List<SchedulerAppointmentDC> { appointment });
|
|
|
|
Model.Appointment2Answer = null;
|
|
Model.AppointmentOid2Answer = null;
|
|
|
|
ReloadAppointments();
|
|
|
|
return PartialView("NotificationsPopupContent", Model);
|
|
}
|
|
|
|
[Authorize]
|
|
public ActionResult ConfirmAllOpenAppointments()
|
|
{
|
|
Model.OpenAppointments = KalenderService.GetAllOpenAppointmentsForEmployee(Model.LoggedInUser.Employee.EmployeeOid);
|
|
|
|
foreach(var openAppointment in Model.OpenAppointments)
|
|
{
|
|
var employee2Appointment = openAppointment.EmployeeList.First(first => first.Employee.Equals(Model.LoggedInUser.Employee));
|
|
|
|
employee2Appointment.ParticipationAnswer = openAppointment.EndDate is null || openAppointment.EndDate > DateTime.Now ? ParticipationAnswer.Zusage : ParticipationAnswer.Verstrichen;
|
|
employee2Appointment.IsPChanged = true;
|
|
employee2Appointment.IsPC_CheckedTs = DateTime.Now;
|
|
}
|
|
|
|
KalenderService.UpdateSchedulerAppointments(Model.OpenAppointments);
|
|
|
|
Model.Appointment2Answer = null;
|
|
Model.AppointmentOid2Answer = null;
|
|
|
|
ReloadAppointments();
|
|
|
|
return PartialView("NotificationsPopupContent", Model);
|
|
}
|
|
|
|
[Authorize]
|
|
public ActionResult RightClickConfirm(int answer, long id)
|
|
{
|
|
var appointments = (List<SchedulerAppointmentDC>) 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<SchedulerAppointmentDC> { 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<long>() : selectedOids.Split(',').Select(long.Parse).ToList();
|
|
|
|
AppointmentModel.SelectedEmployee2SchedulerAppointments = new List<Employee2SchedulerAppointmentDC>();
|
|
|
|
var employees = AppointmentModel.PossibleEmployees.Where(possibleEmployee => selectedEmployeeOids.Contains(possibleEmployee.EmployeeOid)).ToList();
|
|
|
|
foreach(var employee in employees)
|
|
{
|
|
AppointmentModel.SelectedEmployee2SchedulerAppointments.Add(new Employee2SchedulerAppointmentDC { Employee = employee });
|
|
}
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string UpdateAppointmentCustomerSelection(string selectedOids)
|
|
{
|
|
if(selectedOids is null)
|
|
{
|
|
selectedOids = string.Empty;
|
|
}
|
|
|
|
AppointmentModel.SelectedCustomerOids = selectedOids.Length == 0 ? new List<long>() : selectedOids.Split(',').Select(long.Parse).ToList();
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
|
|
[Authorize]
|
|
public string UpdateAppointmentResourceSelection(string selectedOids)
|
|
{
|
|
if(selectedOids is null)
|
|
{
|
|
selectedOids = string.Empty;
|
|
}
|
|
|
|
AppointmentModel.SelectedResourceOids = selectedOids.Length == 0 ? new List<long>() : selectedOids.Split(',').Select(long.Parse).ToList();
|
|
|
|
return LeerzeichenFuerGetMethoden;
|
|
}
|
|
}
|
|
|
|
public class EditFormInfo
|
|
{
|
|
public int PageCount { get; }
|
|
public int PageLimit { get; }
|
|
|
|
public EditFormInfo(int pageCount, int pageLimit)
|
|
{
|
|
PageCount = pageCount;
|
|
PageLimit = pageLimit;
|
|
}
|
|
}
|
|
} |