106 lines
4.8 KiB
C#
106 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BS.Shared.Core
|
|
{
|
|
public static class SchedulerUtils
|
|
{
|
|
public static List<SchedulerAppointmentDC> GenerateSeveralDaysAppointments(List<SchedulerAppointmentDC> severalDaysAppointments)
|
|
{
|
|
var result = new List<SchedulerAppointmentDC>();
|
|
|
|
foreach(var termin in severalDaysAppointments)
|
|
{
|
|
if(termin.StartDate is null || termin.EndDate is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var tage = termin.StartDate.Value.GetDayNumberBetweenTwoDates(termin.EndDate.Value);
|
|
if(tage > 31)
|
|
{
|
|
tage = 31;
|
|
}
|
|
|
|
if(termin.AllDay)
|
|
{
|
|
tage -= 1;
|
|
}
|
|
|
|
if(tage > 0)
|
|
{
|
|
if(termin.AllDay)
|
|
{
|
|
for(var i = 0; i <= tage; i++)
|
|
{
|
|
var isAllDay = termin.AllDay;
|
|
var startDate = new DateTime(termin.StartDate.Value.AddDays(i).Year, termin.StartDate.Value.AddDays(i).Month, termin.StartDate.Value.AddDays(i).Day);
|
|
var endDate = new DateTime(termin.StartDate.Value.AddDays(i + 1).Year, termin.StartDate.Value.AddDays(i + 1).Month, termin.StartDate.Value.AddDays(i + 1).Day);
|
|
|
|
result.Add(CreateAppointment(isAllDay, startDate, endDate, termin));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(var i = 0; i <= tage; i++)
|
|
{
|
|
if(i == 0)
|
|
{
|
|
var startDate = termin.StartDate.Value;
|
|
var endDate = new DateTime(termin.StartDate.Value.AddDays(1).Year, termin.StartDate.Value.AddDays(1).Month, termin.StartDate.Value.AddDays(1).Day);
|
|
|
|
result.Add(CreateAppointment(false, startDate, endDate, termin));
|
|
}
|
|
else if(i == tage)
|
|
{
|
|
var startDate = new DateTime(termin.EndDate.Value.Year, termin.EndDate.Value.Month, termin.EndDate.Value.Day);
|
|
var endDate = termin.EndDate.Value;
|
|
|
|
result.Add(CreateAppointment(false, startDate, endDate, termin));
|
|
}
|
|
else
|
|
{
|
|
var startDate = new DateTime(termin.StartDate.Value.AddDays(i).Year, termin.StartDate.Value.AddDays(i).Month, termin.StartDate.Value.AddDays(i).Day);
|
|
var endDate = new DateTime(termin.StartDate.Value.AddDays(i + 1).Year, termin.StartDate.Value.AddDays(i + 1).Month, termin.StartDate.Value.AddDays(i + 1).Day);
|
|
|
|
result.Add(CreateAppointment(true, startDate, endDate, termin));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static SchedulerAppointmentDC CreateAppointment(bool isAllDay, DateTime startDate, DateTime endDate, SchedulerAppointmentDC appointment)
|
|
{
|
|
return new SchedulerAppointmentDC
|
|
{
|
|
AllDay = isAllDay,
|
|
CustomerList = appointment.CustomerList,
|
|
Description = appointment.Description,
|
|
EmployeeList = appointment.EmployeeList,
|
|
EndDate = endDate,
|
|
FormerBookingSequenceOid = appointment.FormerBookingSequenceOid,
|
|
IsPrivate = appointment.IsPrivate,
|
|
LabelKey = appointment.LabelKey,
|
|
Location = appointment.Location,
|
|
Originator = appointment.Originator,
|
|
RecurrenceInfo = appointment.RecurrenceInfo,
|
|
ReminderInfo = appointment.ReminderInfo,
|
|
ResourceList = appointment.ResourceList,
|
|
StartDate = startDate,
|
|
Status = appointment.Status,
|
|
Subject = appointment.Subject,
|
|
Type = appointment.Type,
|
|
ServiceRecordList = appointment.ServiceRecordList,
|
|
SupportConceptList = appointment.SupportConceptList
|
|
};
|
|
}
|
|
}
|
|
}
|