2025-04-08 16:57:55 +02:00
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
using System;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BeWo.ViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
public abstract class AbstractDCMapperVM<DCType> : AbstractBaseVM where DCType : new()
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly List<string> _DirtyProps = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
private bool? _IsNew;
|
|
|
|
|
|
|
|
|
|
|
|
public AbstractDCMapperVM() { }
|
|
|
|
|
|
|
|
|
|
|
|
public AbstractDCMapperVM(DCType pDataContract, bool pIsNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
_IsNew = pIsNew;
|
|
|
|
|
|
DataContract = pDataContract;
|
|
|
|
|
|
InitByDataContract(DataContract);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-08 16:57:55 +02:00
|
|
|
|
public AbstractDCMapperVM(DCType pDataContract, long? oid) : this(pDataContract, oid is null) { }
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public override bool IsDirty
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _DirtyProps.Count > 0; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsNew
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_IsNew == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _IsNew.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-08 16:57:55 +02:00
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_IsNew = value;
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal DCType DataContract { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DCType CommitToDataContract()
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapToDataContract(DataContract, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DCType CopyToEmptyDataContract()
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapToDataContract(new DCType(), false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void SetDirty(bool newDirty)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!newDirty)
|
|
|
|
|
|
{
|
|
|
|
|
|
_DirtyProps.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract void InitByDataContract(DCType pDataContract);
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract DCType MapToDataContract(DCType pDataContract, bool doCommit);
|
|
|
|
|
|
|
2025-05-13 11:10:24 +02:00
|
|
|
|
internal virtual void UpdateByDataContract(DCType pDataContract)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
protected void StoreDirtyInformation(bool pDirty, string pPropName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_DirtyProps.Contains(pPropName) && !pDirty)
|
|
|
|
|
|
{
|
|
|
|
|
|
_DirtyProps.Remove(pPropName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!_DirtyProps.Contains(pPropName) && pDirty)
|
|
|
|
|
|
{
|
|
|
|
|
|
_DirtyProps.Add(pPropName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|