306 lines
14 KiB
C#
306 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using BeWoPlanerMobil.Util;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWoPlanerMobil.Models
|
|
{
|
|
public class SchedulerModel : AbstractModel
|
|
{
|
|
public SchedulerModel()
|
|
{
|
|
SessionModel = new SchedulerSessionModel();
|
|
SessionModel.ResetValues();
|
|
}
|
|
|
|
public SchedulerSessionModel SchedulerSessionModel => SessionModel as SchedulerSessionModel;
|
|
|
|
public List<long> TeamMemberCustomerOids { get; set; }
|
|
|
|
public DateTime SelectedDate
|
|
{
|
|
get => SchedulerSessionModel.SelectedDate;
|
|
set => SchedulerSessionModel.SelectedDate = value;
|
|
}
|
|
|
|
public long? SelectedAppointmentOid
|
|
{
|
|
get => SchedulerSessionModel.SelectedAppointmentOid;
|
|
set => SchedulerSessionModel.SelectedAppointmentOid = value;
|
|
}
|
|
|
|
public SchedulerAppointmentDC SelectedAppointment { get; set; }
|
|
|
|
|
|
public List<SchedulerAppointmentDC> Appointments { get; set; }
|
|
|
|
public List<AppointmentListItem> AppointmentListItems { get; set; }
|
|
|
|
public bool HasRightToEditAppointment(string identifier)
|
|
{
|
|
var appointment = AppointmentListItems.FirstOrDefault(app => app.Identifier.Equals(identifier))?.SchedulerAppointment;
|
|
|
|
return appointment != null && Utils.CheckSchedulerRights(appointment.CustomerList, appointment.ResourceList, appointment.EmployeeList, appointment.Originator, appointment.SchedulerAppointmentOid is null, SchedulerRightsCheckType.Edit, LoggedInUser, TeamMemberCustomerOids ?? new List<long>());
|
|
}
|
|
|
|
public string DescriptionToEdit => SelectedAppointment?.Description ?? string.Empty;
|
|
|
|
public string SubjectToEdit => SelectedAppointment?.Subject ?? string.Empty;
|
|
|
|
public string StartDateToEdit => SelectedAppointment?.StartDate?.ToString("yyyy-MM-ddTHH:mm") ?? SelectedDate.ToString("yyyy-MM-ddTHH:mm");
|
|
|
|
public string EndDateToEdit => SelectedAppointment?.EndDate?.ToString("yyyy-MM-ddTHH:mm") ?? SelectedDate.ToString("yyyy-MM-ddTHH:mm");
|
|
|
|
public string LocationToEdit => SelectedAppointment?.Location ?? string.Empty;
|
|
|
|
public List<ResourceDC> AllResources
|
|
{
|
|
get
|
|
{
|
|
var allResources = new List<ResourceDC>();
|
|
|
|
foreach(var cat2Res in ResourceCategories2Resources)
|
|
{
|
|
allResources.AddRangeIfElementsNotIn(cat2Res.Value);
|
|
}
|
|
|
|
return allResources.OrderBy(resource => resource.Name).ToList();
|
|
}
|
|
}
|
|
|
|
public List<long> SelectedResourceOids
|
|
{
|
|
get => SchedulerSessionModel.SelectedResourceOids;
|
|
set => SchedulerSessionModel.SelectedResourceOids = value;
|
|
}
|
|
|
|
public List<ResourceDC> SelectedResources { get; set; }
|
|
|
|
public Dictionary<ValueListEntryDC, List<ResourceDC>> ResourceCategories2Resources { get; set; } = new Dictionary<ValueListEntryDC, List<ResourceDC>>();
|
|
|
|
|
|
[Display(Name = "Kalenderansicht")]
|
|
public string SelectedSchedulerView { get; set; } = "1";
|
|
|
|
public List<SelectListItem> SchedulerViewList
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>
|
|
{
|
|
new SelectListItem { Text = "1", Value = "1" },
|
|
new SelectListItem { Text = "5", Value = "5" },
|
|
new SelectListItem { Text = "7", Value = "7" }
|
|
};
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public WeekViewObject WeekViewObject { get; set; }
|
|
|
|
public List<CompactEmployeeDC> AllEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<long> SelectedEmployeeOids
|
|
{
|
|
get => SchedulerSessionModel.SelectedEmployeeOids;
|
|
set => SchedulerSessionModel.SelectedEmployeeOids = value;
|
|
}
|
|
|
|
public List<CompactEmployeeDC> SelectedEmployees { get; set; }
|
|
|
|
public List<CompactCustomerDC> AllCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<long> SelectedCustomerOids
|
|
{
|
|
get => SchedulerSessionModel.SelectedCustomerOids;
|
|
set => SchedulerSessionModel.SelectedCustomerOids = value;
|
|
}
|
|
|
|
public List<CompactCustomerDC> SelectedCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public bool IsInEditMode => SelectedAppointmentOid.HasValue;
|
|
|
|
// ToDo: Überarbeiten? Es kam das Ansehen hinzu
|
|
public bool HasResourcesEmployeesOrCustomers { get; set; }
|
|
|
|
public bool ShowEmployeeButton => IsInEditMode ? HasRightToInsertEmployeeAppointments : HasRightToEditEmployeeAppointments;
|
|
public bool ShowCustomerButton => IsInEditMode ? HasRightToInsertCustomerAppointments : HasRightToEditCustomerAppointments;
|
|
|
|
//IntervalFinder
|
|
public List<long> SelectedEmployeeOidsForIntervalFinder
|
|
{
|
|
get => SchedulerSessionModel.SelectedEmployeeOidsForIntervalFinder;
|
|
set => SchedulerSessionModel.SelectedEmployeeOidsForIntervalFinder = value;
|
|
}
|
|
public List<CompactEmployeeDC> SelectedEmployeesForIntervalFinder { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<long> SelectedCustomerOidsForIntervalFinder
|
|
{
|
|
get => SchedulerSessionModel.SelectedCustomerOidsForIntervalFinder;
|
|
set => SchedulerSessionModel.SelectedCustomerOidsForIntervalFinder = value;
|
|
}
|
|
public List<CompactCustomerDC> SelectedCustomersForIntervalFinder { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<long> SelectedResourceOidsForIntervalFinder
|
|
{
|
|
get => SchedulerSessionModel.SelectedResourceOidsForIntervalFinder;
|
|
set => SchedulerSessionModel.SelectedResourceOidsForIntervalFinder = value;
|
|
}
|
|
public List<ResourceDC> SelectedResourcesForIntervalFinder { get; set; } = new List<ResourceDC>();
|
|
|
|
public Dictionary<DateTimeSpan, Dictionary<DateTime, bool>> FreeIntervals { get; set; } = new Dictionary<DateTimeSpan, Dictionary<DateTime, bool>>();
|
|
|
|
public List<DateTime> FreeIntervalDays
|
|
{
|
|
get
|
|
{
|
|
var days = new List<DateTime>();
|
|
|
|
foreach(var date2HasFreeSlot in FreeIntervals.Values)
|
|
{
|
|
foreach(var date in date2HasFreeSlot.Keys)
|
|
{
|
|
days.AddIfNotIn(date.Date);
|
|
}
|
|
}
|
|
|
|
return days;
|
|
}
|
|
}
|
|
|
|
public bool IsInIntervalFinderMode
|
|
{
|
|
get => SchedulerSessionModel.IsInIntervalFinderMode;
|
|
set => SchedulerSessionModel.IsInIntervalFinderMode = value;
|
|
}
|
|
|
|
public DateTime? IntervalStartDate
|
|
{
|
|
get => SchedulerSessionModel.IntervalStartDate;
|
|
set => SchedulerSessionModel.IntervalStartDate = value;
|
|
}
|
|
|
|
public DateTime? IntervalEndDate
|
|
{
|
|
get => SchedulerSessionModel.IntervalEndDate;
|
|
set => SchedulerSessionModel.IntervalEndDate = value;
|
|
}
|
|
|
|
public string IntervalStartDateStr => IntervalStartDate.HasValue ? IntervalStartDate.Value.ToString("yyyy-MM-ddTHH:mm") : string.Empty;
|
|
public string IntervalEndDateStr => IntervalEndDate.HasValue ? IntervalEndDate.Value.ToString("yyyy-MM-ddTHH:mm") : string.Empty;
|
|
public string IntervalStartTimeStr => IntervalStartDate.HasValue ? $"{IntervalStartDate:HH:mm}" : string.Empty;
|
|
public string IntervalEndTimeStr => IntervalEndDate.HasValue ? $"{IntervalEndDate:HH:mm}" : string.Empty;
|
|
|
|
public int? IntervalDuration
|
|
{
|
|
get => SchedulerSessionModel.IntervalDuration;
|
|
set => SchedulerSessionModel.IntervalDuration = value;
|
|
}
|
|
|
|
public string IntervalDurationStr => IntervalDuration.HasValue ? $"{IntervalDuration}" : string.Empty;
|
|
|
|
[Display(Name = "Ganztägig")]
|
|
public bool IsAllDay
|
|
{
|
|
get => SchedulerSessionModel.IsAllDay;
|
|
set => SchedulerSessionModel.IsAllDay = value;
|
|
}
|
|
|
|
[Display(Name = "Privat")]
|
|
public bool IsPrivate
|
|
{
|
|
get => SchedulerSessionModel.IsPrivate;
|
|
set => SchedulerSessionModel.IsPrivate = value;
|
|
}
|
|
|
|
|
|
public List<CompactEmployeeDC> MyTeamEmployees { get; set; }
|
|
|
|
public List<long> SelectedResourceOidsForFiltering
|
|
{
|
|
get => SchedulerSessionModel.SelectedResourceOidsForFiltering;
|
|
set => SchedulerSessionModel.SelectedResourceOidsForFiltering = value;
|
|
}
|
|
public List<ResourceDC> SelectedResourcesForFiltering { get; set; }
|
|
|
|
public List<long> SelectedEmployeeOidsForFiltering
|
|
{
|
|
get => SchedulerSessionModel.SelectedEmployeeOidsForFiltering;
|
|
set => SchedulerSessionModel.SelectedEmployeeOidsForFiltering = value;
|
|
}
|
|
public List<CompactEmployeeDC> SelectedEmployeesForFiltering { get; set; }
|
|
|
|
public List<long> SelectedCustomerOidsForFiltering
|
|
{
|
|
get => SchedulerSessionModel.SelectedCustomerOidsForFiltering;
|
|
set => SchedulerSessionModel.SelectedCustomerOidsForFiltering = value;
|
|
}
|
|
public List<CompactCustomerDC> SelectedCustomersForFiltering { get; set; }
|
|
|
|
public List<CompactTeamDC> MyTeams { get; set; } = new List<CompactTeamDC>();
|
|
|
|
public bool ShouldLoadTasks
|
|
{
|
|
get => SchedulerSessionModel.ShouldLoadTasks;
|
|
set => SchedulerSessionModel.ShouldLoadTasks = value;
|
|
}
|
|
}
|
|
|
|
public class WeekViewObject
|
|
{
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> MondayAppointments { get; set; }
|
|
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> TuesdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> WednesdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> ThursdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> FridayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> SaturdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> SundayAppointments { get; set; }
|
|
|
|
public WeekViewObject(IEnumerable<SchedulerAppointmentDC> appointments, DateTime monday, EmployeeDC loggedInEmployee)
|
|
{
|
|
var first = monday.Date;
|
|
var last = first.AddDays(6);
|
|
|
|
var tuesday = first.AddDays(1);
|
|
var wednesday = first.AddDays(2);
|
|
var thursday = first.AddDays(3);
|
|
var friday = first.AddDays(4);
|
|
var saturday = first.AddDays(5);
|
|
|
|
var blubbtest = appointments.Where(a => a.StartDate >= first || a.StartDate <= last).ToList();
|
|
|
|
var mondays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Monday);
|
|
var tuesdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Tuesday);
|
|
var wednesdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Wednesday);
|
|
var thursdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Thursday);
|
|
var fridays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Friday);
|
|
var saturdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Saturday);
|
|
var sundays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Sunday);
|
|
|
|
MondayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(first, new List<AppointmentListItem>());
|
|
TuesdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(tuesday, new List<AppointmentListItem>());
|
|
WednesdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(wednesday, new List<AppointmentListItem>());
|
|
ThursdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(thursday, new List<AppointmentListItem>());
|
|
FridayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(friday, new List<AppointmentListItem>());
|
|
SaturdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(saturday, new List<AppointmentListItem>());
|
|
SundayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(last, new List<AppointmentListItem>());
|
|
|
|
mondays.DoForEach(app => MondayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
tuesdays.DoForEach(app => TuesdayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
wednesdays.DoForEach(app => WednesdayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
thursdays.DoForEach(app => ThursdayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
fridays.DoForEach(app => FridayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
saturdays.DoForEach(app => SaturdayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
sundays.DoForEach(app => SundayAppointments.Value.Add(new AppointmentListItem("", app)));
|
|
}
|
|
}
|
|
} |