168 lines
6.8 KiB
C#
168 lines
6.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using BeWo.Data;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
using DevExpress.XtraCharts.Native;
|
|
|
|
namespace BeWo.Service.DCEntityMapper
|
|
{
|
|
public class SchedulerAppointmentDC_SchedulerAppointment : AbstractIDCEntityMapper<SchedulerAppointment, SchedulerAppointmentDC>
|
|
{
|
|
public override SchedulerAppointmentDC MergeWithDC(SchedulerAppointment pEntity, SchedulerAppointmentDC pDataContract)
|
|
{
|
|
pDataContract.SchedulerAppointmentOid = pEntity.Oid;
|
|
pDataContract.NewSchedulerAppointmentVersion = pEntity.Version;
|
|
|
|
pDataContract.AllDay = pEntity.AllDay;
|
|
pDataContract.EndDate = pEntity.EndDate;
|
|
pDataContract.StartDate = pEntity.StartDate;
|
|
pDataContract.Status = pEntity.Status;
|
|
pDataContract.Subject = pEntity.Subject;
|
|
pDataContract.Type = pEntity.Type;
|
|
pDataContract.Location = pEntity.Location;
|
|
pDataContract.Description = pEntity.Notice;
|
|
pDataContract.RecurrenceInfo = pEntity.RecurrenceInfo;
|
|
pDataContract.ReminderInfo = pEntity.ReminderInfo;
|
|
|
|
pDataContract.IsPrivate = pEntity.IsPrivate;
|
|
pDataContract.CustomerList = MapperFactory.CompactCustomerDC_Customer.MapToNewDCs(pEntity.CustomerList);
|
|
pDataContract.ResourceList = MapperFactory.ResourceDC_Resource.MapToNewDCs(pEntity.ResourceList);
|
|
pDataContract.EmployeeList = MapperFactory.Employee2SchedulerAppointmentDC_Employee2SchedulerAppointment.MapToNewDCs(pEntity.EmployeeList);
|
|
|
|
pDataContract.IsTask = pEntity.IsTask;
|
|
pDataContract.TaskDescription = pEntity.TaskDescription;
|
|
pDataContract.CompletedNotice = pEntity.CompletedNotice;
|
|
pDataContract.CompletedUser = pEntity.CompletedUser;
|
|
pDataContract.CompletedDate = pEntity.CompletedDate;
|
|
|
|
pDataContract.DueDate = pEntity.DueDate;
|
|
pDataContract.FormerBookingSequenceOid = pEntity.FormerBookingSequenceOid;
|
|
pDataContract.SupportConceptList = MapperFactory.CompactSupportConceptDC_SupportConcept.MapToNewDCs(pEntity.SupportConceptList);
|
|
pDataContract.FormerTaskOid = pEntity.FormerTaskOid;
|
|
pDataContract.HasServiceRecordEntry = pEntity.HasServiceRecordEntry;
|
|
|
|
if(pEntity.Originator != null)
|
|
{
|
|
pDataContract.Originator = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(pEntity.Originator);
|
|
}
|
|
|
|
pDataContract.ActivationType = pEntity.IsActive;
|
|
|
|
pDataContract.CanBeEdited = true;
|
|
|
|
pDataContract.ServiceRecordList = MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDCs(pEntity.ServiceRecordList);
|
|
|
|
if (pDataContract.HasServiceRecordEntry && pDataContract.ServiceRecordList.Count == 0)
|
|
{
|
|
// Add dummy ServiceRecord
|
|
pDataContract.ServiceRecordList.Add(new ServiceRecordDC());
|
|
}
|
|
return pDataContract;
|
|
}
|
|
|
|
public override SchedulerAppointment MergeWithEntity(SchedulerAppointmentDC pDataContract, SchedulerAppointment pEntity)
|
|
{
|
|
ConcurrencyCheck(pDataContract.NewSchedulerAppointmentVersion, pEntity);
|
|
|
|
pEntity.Oid = pDataContract.SchedulerAppointmentOid;
|
|
pEntity.Version = pDataContract.NewSchedulerAppointmentVersion;
|
|
pEntity.AllDay = pDataContract.AllDay;
|
|
pEntity.EndDate = pDataContract.EndDate;
|
|
pEntity.StartDate = pDataContract.StartDate;
|
|
pEntity.Status = pDataContract.Status;
|
|
pEntity.Subject = pDataContract.Subject;
|
|
pEntity.Type = pDataContract.Type;
|
|
pEntity.Location = pDataContract.Location;
|
|
pEntity.Notice = pDataContract.Description;
|
|
pEntity.RecurrenceInfo = pDataContract.RecurrenceInfo;
|
|
pEntity.ReminderInfo = pDataContract.ReminderInfo;
|
|
pEntity.FormerBookingSequenceOid = pDataContract.FormerBookingSequenceOid;
|
|
pEntity.IsTask = pDataContract.IsTask;
|
|
pEntity.TaskDescription = pDataContract.TaskDescription;
|
|
pEntity.CompletedNotice = pDataContract.CompletedNotice;
|
|
|
|
|
|
if(!pEntity.CompletedDate.HasValue && pDataContract.CompletedDate.HasValue)
|
|
{
|
|
ApplicationUser user;
|
|
|
|
if(LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
|
|
{
|
|
user = LoggedInUserOperationContextExt.Current.User;
|
|
}
|
|
else
|
|
{
|
|
user = SessionFacade.LoggedInUser;
|
|
}
|
|
|
|
if(user?.Employee != null)
|
|
{
|
|
pEntity.CompletedUser = user.Employee.Person.FirstNameLastName;
|
|
}
|
|
}
|
|
|
|
pEntity.CompletedDate = pDataContract.CompletedDate;
|
|
pEntity.DueDate = pDataContract.DueDate;
|
|
pEntity.FormerTaskOid = pDataContract.FormerTaskOid;
|
|
|
|
if(pDataContract.Originator != null)
|
|
{
|
|
pEntity.Originator = MapperFactory.CompactEmployeeDC_Employee.MapToNewEntity(pDataContract.Originator);
|
|
}
|
|
|
|
pEntity.IsPrivate = pDataContract.IsPrivate;
|
|
pEntity.HasServiceRecordEntry = pDataContract.HasServiceRecordEntry;
|
|
|
|
try
|
|
{
|
|
if(pDataContract.EmployeeList != null)
|
|
{
|
|
pEntity.EmployeeList = DAOFactory.GenericDAO.LoadByIDs<Employee2SchedulerAppointment>(pDataContract.EmployeeList.Select(e => e.Employee2SchedulerAppointmentOid.Value));
|
|
}
|
|
|
|
if(pDataContract.CustomerList != null)
|
|
{
|
|
pEntity.CustomerList = DAOFactory.GenericDAO.LoadByIDs<Customer>(pDataContract.CustomerList.Select(c => c.CustomerOid));
|
|
}
|
|
|
|
if(pDataContract.ResourceList != null)
|
|
{
|
|
pEntity.ResourceList = DAOFactory.GenericDAO.LoadByIDs<Resource>(pDataContract.ResourceList.Select(r => r.ResourceOid.Value));
|
|
}
|
|
|
|
if(pDataContract.SupportConceptList != null)
|
|
{
|
|
pEntity.SupportConceptList = DAOFactory.GenericDAO.LoadByIDs<SupportConcept>(pDataContract.SupportConceptList.Select(s => s.SupportConceptOid));
|
|
}
|
|
|
|
if(!(pDataContract.ServiceRecordList is null))
|
|
{
|
|
pEntity.ServiceRecordList = DAOFactory.GenericDAO.LoadByIDs<ServiceRecord>(pDataContract.ServiceRecordList.Select(sr => sr.ServiceRecordOid.Value));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new InternalException(e.Message);
|
|
}
|
|
|
|
pEntity.IsActive = pDataContract.ActivationType;
|
|
|
|
return pEntity;
|
|
}
|
|
|
|
protected override bool AreDCAndEntityEqual(SchedulerAppointmentDC pDC, SchedulerAppointment pEntity)
|
|
{
|
|
if(pDC.SchedulerAppointmentOid == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return pDC.SchedulerAppointmentOid == pEntity.Oid;
|
|
}
|
|
}
|
|
}
|