Files
BeWoPlaner/BeWo/ViewModel/TextModuleVM.cs

268 lines
7.5 KiB
C#
Raw Normal View History

2017-09-26 13:30:20 +02:00
using System.Windows;
using BeWo.ServiceProxy;
using BeWo.Validation;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
namespace BeWo.ViewModel
{
public class TextModuleVM : AbstractDCMapperVM<TextModuleDC>
{
private int _Position;
private string _Text;
private string _Name;
private CompactEmployeeDC _Employee;
private ServiceCategoryDC _ServiceCategory;
private bool _IsOnlyForEmployee;
private bool _IsParent;
2018-01-05 19:13:18 -04:00
private bool _IsExpanded;
2017-09-26 13:30:20 +02:00
private TextModuleVM _Parent;
private ActivationTypeId _ActivationType;
public TextModuleVM(TextModuleDC pDataContract) : base(pDataContract, pDataContract.TextModuleOid == null) {}
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
public bool IsExpanded
{
get => _IsExpanded;
set
{
if(AreDifferent(_IsExpanded, value))
{
_IsExpanded = value;
StoreDirtyInformation(AreDifferent(DataContract.IsExpanded, value), nameof(IsExpanded));
FirePropertyChanged(nameof(IsExpanded));
}
}
}
2017-09-26 13:30:20 +02:00
public ServiceCategoryDC ServiceCategory
{
2018-01-05 19:13:18 -04:00
get => _ServiceCategory;
2017-09-26 13:30:20 +02:00
set
{
if (AreDifferent(_ServiceCategory, value))
{
_ServiceCategory = value;
StoreDirtyInformation(AreDifferent(DataContract.ServiceCategory, value), nameof(ServiceCategory));
FirePropertyChanged(nameof(ServiceCategory));
}
}
}
public CompactEmployeeDC Employee
{
2018-01-05 19:13:18 -04:00
get => _Employee;
2017-09-26 13:30:20 +02:00
set
{
if (AreDifferent(_Employee, value))
{
_Employee = value;
StoreDirtyInformation(AreDifferent(DataContract.Employee, value), nameof(Employee));
FirePropertyChanged(nameof(Employee));
}
}
}
public ActivationTypeId ActivationType
{
get => _ActivationType;
set
{
if(AreDifferent(_ActivationType, value))
{
_ActivationType = value;
StoreDirtyInformation(AreDifferent(DataContract.ActivationType, value), nameof(ActivationType));
FirePropertyChanged(nameof(ActivationType));
}
}
}
2017-09-26 13:30:20 +02:00
public int Position
{
2018-01-05 19:13:18 -04:00
get => _Position;
2017-09-26 13:30:20 +02:00
set
{
if (AreDifferent(_Position, value))
{
_Position = value;
StoreDirtyInformation(AreDifferent(DataContract.Position, value), nameof(Position));
FirePropertyChanged(nameof(Position));
}
}
}
public string Text
{
2018-01-05 19:13:18 -04:00
get => _Text;
2017-09-26 13:30:20 +02:00
set
{
if (AreDifferent(_Text, value))
{
_Text = value;
StoreDirtyInformation(AreDifferent(DataContract.Text, value), nameof(Text));
FirePropertyChanged(nameof(Text));
}
}
}
public bool IsOnlyForEmployee
{
2018-01-05 19:13:18 -04:00
get => _IsOnlyForEmployee;
2017-09-26 13:30:20 +02:00
set
{
if (AreDifferent(_IsOnlyForEmployee, value))
{
_IsOnlyForEmployee = value;
StoreDirtyInformation(AreDifferent(DataContract.IsOnlyForEmployee, value), nameof(IsOnlyForEmployee));
FirePropertyChanged(nameof(IsOnlyForEmployee));
}
}
}
public bool IsParent
{
2018-01-05 19:13:18 -04:00
get => _IsParent;
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
set
2017-09-26 13:30:20 +02:00
{
if(AreDifferent(_IsParent, value))
{
_IsParent = value;
StoreDirtyInformation(AreDifferent(DataContract.IsParent, value), nameof(IsParent));
FirePropertyChanged(nameof(IsParent));
}
}
}
public TextModuleVM Parent
{
2018-01-05 19:13:18 -04:00
get => _Parent;
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
set
2017-09-26 13:30:20 +02:00
{
if(AreDifferent(_Parent, value) && AreDifferent(value, this))
{
_Parent = value;
StoreDirtyInformation(AreDifferent(DataContract.Parent, value), nameof(Parent));
FirePropertyChanged(nameof(Parent));
}
}
}
public FontWeight FontWeight => _IsParent ? FontWeights.Bold : FontWeights.Normal;
public long? KeyField => DataContract?.TextModuleOid;
public long? ParentField => Parent?.DataContract?.TextModuleOid;
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
public string Name
{
2018-01-05 19:13:18 -04:00
get => _Name;
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
set
2017-09-26 13:30:20 +02:00
{
if (AreDifferent(_Name, value))
{
_Name = value;
StoreDirtyInformation(AreDifferent(DataContract.Name, value), nameof(Name));
FirePropertyChanged(nameof(Name));
}
}
}
protected override void InitByDataContract(TextModuleDC pDataContract)
{
if (!IsNew)
{
_ServiceCategory = pDataContract.ServiceCategory;
_Text = pDataContract.Text;
_Position = pDataContract.Position;
_Name = pDataContract.Name;
_Employee = pDataContract.Employee;
_IsOnlyForEmployee = pDataContract.IsOnlyForEmployee;
_IsParent = pDataContract.IsParent;
_Parent = pDataContract.Parent != null ? new TextModuleVM(pDataContract.Parent) : null;
2018-01-05 19:13:18 -04:00
_IsExpanded = pDataContract.IsExpanded;
2017-09-26 13:30:20 +02:00
}
else
{
ServiceFacade.DoEmployeeServiceSync(s => _Employee = s.LoadCompactEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value));
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineNurEigeneBearbeiten) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineAlleBearbeiten))
2017-09-26 13:30:20 +02:00
{
_IsOnlyForEmployee = true;
}
}
}
protected override TextModuleDC MapToDataContract(TextModuleDC pDataContract, bool doCommit)
{
2018-01-05 19:13:18 -04:00
pDataContract.Text = _Text;
pDataContract.Position = _Position;
pDataContract.Name = _Name;
pDataContract.IsParent = _IsParent;
pDataContract.IsExpanded = _IsExpanded;
pDataContract.ActivationType = _ActivationType;
2017-09-26 13:30:20 +02:00
pDataContract.IsOnlyForEmployee = _IsOnlyForEmployee;
2018-01-05 19:13:18 -04:00
pDataContract.Parent = _Parent?.CommitToDataContract();
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
pDataContract.Employee = _Employee;
2017-09-26 13:30:20 +02:00
2018-01-05 19:13:18 -04:00
pDataContract.ServiceCategory = _ServiceCategory;
2017-09-26 13:30:20 +02:00
return pDataContract;
}
public override bool Equals(object pObj)
{
if (!(pObj is TextModuleVM))
{
return false;
}
var obj = (TextModuleVM) pObj;
return
Equals(IsNew, obj.IsNew) &&
Equals(ServiceCategory, obj.ServiceCategory) &&
Equals(Text, obj.Text) &&
Equals(Position, obj.Position) &&
Equals(Parent, obj.Parent) &&
Equals(Name, obj.Name) &&
Equals(Employee, obj.Employee) &&
Equals(IsOnlyForEmployee, obj.IsOnlyForEmployee) &&
Equals(IsParent, obj.IsParent) &&
Equals(IsDirty, obj.IsDirty);
}
public override string ToString()
{
return _Name;
}
}
}