237 lines
11 KiB
C#
237 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using BeWoPlanerMobil.Service;
|
|
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 DateTime SelectedDate { get; set; } = DateTime.Today;
|
|
|
|
public SchedulerAppointmentDC SelectedAppointment { get; set; }
|
|
|
|
public List<SchedulerAppointmentDC> Appointments { get; set; } = new List<SchedulerAppointmentDC>();
|
|
|
|
public List<AppointmentListItem> AppointmentListItems
|
|
{
|
|
get
|
|
{
|
|
var result = new List<AppointmentListItem>();
|
|
|
|
Appointments.DoForEach(app => result.AddIfNotIn(new AppointmentListItem(app)));
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public bool HasRightToEditAppointment(long? appointmentOid)
|
|
{
|
|
if (appointmentOid == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var appointment = Appointments.FirstOrDefault(app => app.SchedulerAppointmentOid.HasValue && app.SchedulerAppointmentOid.Value == appointmentOid);
|
|
|
|
if (appointment == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var hasCustomers = appointment.CustomerList.Any();
|
|
var hasEmployees = appointment.EmployeeList.Any();
|
|
var hasResources = appointment.ResourceList.Any();
|
|
|
|
var result = true;
|
|
|
|
if(hasEmployees)
|
|
{
|
|
result = hasResources ?
|
|
MobileSessionFacade.CheckForUserRight(UserRightType.KalenderRessourcentermineAndererAendern) :
|
|
MobileSessionFacade.CheckForUserRight(UserRightType.KalenderMitarbeitertermineAendern);
|
|
|
|
if (appointment.CustomerList.Any())
|
|
{
|
|
result = MobileSessionFacade.CheckForUserRight(UserRightType.KalenderKliententermineAendern) && result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(hasCustomers && hasResources)
|
|
{
|
|
result = MobileSessionFacade.CheckForUserRight(UserRightType.KalenderKliententermineAendern) && MobileSessionFacade.CheckForUserRight(UserRightType.KalenderRessourcentermineAendern);
|
|
}
|
|
else if(hasCustomers)
|
|
{
|
|
result = MobileSessionFacade.CheckForUserRight(UserRightType.KalenderKliententermineAendern);
|
|
}
|
|
else if(hasResources)
|
|
{
|
|
result = MobileSessionFacade.CheckForUserRight(UserRightType.KalenderRessourcentermineAendern);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public string DescriptionToEdit => SelectedAppointment?.Description ?? string.Empty;
|
|
|
|
public string SubjectToEdit => SelectedAppointment?.Subject ?? string.Empty;
|
|
|
|
public string StartDateToEdit => SelectedAppointment?.StartDate?.ToShortDateString() ?? SelectedDate.ToShortDateString();
|
|
|
|
public string EndDateToEdit => SelectedAppointment?.EndDate?.ToShortDateString() ?? SelectedDate.ToShortDateString();
|
|
|
|
public string StartTimeToEdit => SelectedAppointment?.StartDate?.ToShortTimeString() ?? string.Empty;
|
|
|
|
public string EndTimeToEdit => SelectedAppointment?.EndDate?.ToShortTimeString() ?? string.Empty;
|
|
|
|
public string LocationToEdit => SelectedAppointment?.Location ?? string.Empty;
|
|
|
|
public List<ResourceDC> AllResources { get; set; } = new List<ResourceDC>();
|
|
|
|
public List<ResourceDC> SelectedResources { get; set; } = new List<ResourceDC>();
|
|
|
|
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<CompactEmployeeDC> SelectedEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<CompactCustomerDC> AllCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<CompactCustomerDC> SelectedCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public bool IsInEditMode => SelectedAppointment != null;
|
|
|
|
public bool HasResourcesEmployeesOrCustomers
|
|
{
|
|
get
|
|
{
|
|
var isOwnAppointment = !IsInEditMode || SelectedAppointment.Originator.EmployeeOid == Employee.EmployeeOid;
|
|
|
|
var v1 = HasRightToInsertEmployeeAppointments || IsInEditMode && HasRightToEditEmployeeAppointments;
|
|
|
|
var v2 = HasRightToInsertRessourceAppointments || IsInEditMode && HasRightToEditResourceAppointments;
|
|
|
|
if (IsInEditMode && !isOwnAppointment)
|
|
{
|
|
v2 = HasRightToEditOthersResourceAppointments;
|
|
}
|
|
|
|
var v3 = HasRightToInsertCustomerAppointments || IsInEditMode && HasRightToEditCustomerAppointments;
|
|
|
|
return v1 || v2 || v3;
|
|
}
|
|
}
|
|
|
|
public bool ShowEmployeeButton => IsInEditMode ? HasRightToInsertEmployeeAppointments : HasRightToEditEmployeeAppointments;
|
|
public bool ShowCustomerButton => IsInEditMode ? HasRightToInsertCustomerAppointments : HasRightToEditCustomerAppointments;
|
|
|
|
//IntervalFinder
|
|
public List<CompactEmployeeDC> SelectedEmployeesForIntervalFinder { get; set; } = new List<CompactEmployeeDC>();
|
|
public List<CompactCustomerDC> SelectedCustomersForIntervalFinder { get; set; } = new List<CompactCustomerDC>();
|
|
public List<ResourceDC> SelectedResourcesForIntervalFinder { get; set; } = new List<ResourceDC>();
|
|
|
|
public Dictionary<DateTime, List<DateTimeSpan>> FreeIntervals { get; set; } = new Dictionary<DateTime, List<DateTimeSpan>>();
|
|
|
|
public bool IsInIntervalFinderMode { get; set; }
|
|
public DateTime? IntervalStartDate { get; set; }
|
|
public DateTime? IntervalEndDate { get; set; }
|
|
|
|
public string IntervalStartDateStr => IntervalStartDate.HasValue ? $"{IntervalStartDate:dd.MM.yyyy}" : string.Empty;
|
|
public string IntervalEndDateStr => IntervalEndDate.HasValue ? $"{IntervalEndDate:dd.MM.yyyy}" : 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; set; }
|
|
|
|
public string IntervalDurationStr => IntervalDuration.HasValue ? $"{IntervalDuration}" : string.Empty;
|
|
|
|
[Display(Name = "Ganztägig")]
|
|
public bool IsAllDay { get; set; }
|
|
|
|
[Display(Name = "Privat")]
|
|
public bool IsPrivate { get; set; }
|
|
}
|
|
|
|
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)
|
|
{
|
|
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)));
|
|
}
|
|
}
|
|
} |