Files
BeWoPlaner/BeWoPlanerMobil/Models/SchedulerModel.cs
Lyndon Jetten dd37254bd8 Mobilversion:
#if DEBUG in .cshtml-Dateien integriert
2020-07-20 14:02:04 +02:00

104 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWoPlanerMobil.Service;
using BeWoPlanerMobil.Util;
using BS.Shared;
using BS.Shared.DataContracts;
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>>();
public List<SchedulerAppointmentDC> RecurringAppointments { get; set; } = new List<SchedulerAppointmentDC>();
}
}