-
This commit is contained in:
239
BeWo/ViewModel/TextModuleVM.cs
Normal file
239
BeWo/ViewModel/TextModuleVM.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
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;
|
||||
|
||||
private TextModuleVM _Parent;
|
||||
|
||||
|
||||
public TextModuleVM(TextModuleDC pDataContract) : base(pDataContract, pDataContract.TextModuleOid == null) {}
|
||||
|
||||
|
||||
public ServiceCategoryDC ServiceCategory
|
||||
{
|
||||
get { return _ServiceCategory; }
|
||||
|
||||
set
|
||||
{
|
||||
if (AreDifferent(_ServiceCategory, value))
|
||||
{
|
||||
_ServiceCategory = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.ServiceCategory, value), nameof(ServiceCategory));
|
||||
FirePropertyChanged(nameof(ServiceCategory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CompactEmployeeDC Employee
|
||||
{
|
||||
get { return _Employee; }
|
||||
|
||||
set
|
||||
{
|
||||
if (AreDifferent(_Employee, value))
|
||||
{
|
||||
_Employee = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.Employee, value), nameof(Employee));
|
||||
FirePropertyChanged(nameof(Employee));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Position
|
||||
{
|
||||
get { return _Position; }
|
||||
|
||||
set
|
||||
{
|
||||
if (AreDifferent(_Position, value))
|
||||
{
|
||||
_Position = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.Position, value), nameof(Position));
|
||||
FirePropertyChanged(nameof(Position));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return _Text; }
|
||||
|
||||
set
|
||||
{
|
||||
if (AreDifferent(_Text, value))
|
||||
{
|
||||
_Text = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.Text, value), nameof(Text));
|
||||
FirePropertyChanged(nameof(Text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOnlyForEmployee
|
||||
{
|
||||
get { return _IsOnlyForEmployee; }
|
||||
|
||||
set
|
||||
{
|
||||
if (AreDifferent(_IsOnlyForEmployee, value))
|
||||
{
|
||||
_IsOnlyForEmployee = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.IsOnlyForEmployee, value), nameof(IsOnlyForEmployee));
|
||||
FirePropertyChanged(nameof(IsOnlyForEmployee));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsParent
|
||||
{
|
||||
get { return _IsParent; }
|
||||
|
||||
set
|
||||
{
|
||||
if(AreDifferent(_IsParent, value))
|
||||
{
|
||||
_IsParent = value;
|
||||
StoreDirtyInformation(AreDifferent(DataContract.IsParent, value), nameof(IsParent));
|
||||
FirePropertyChanged(nameof(IsParent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextModuleVM Parent
|
||||
{
|
||||
get { return _Parent; }
|
||||
|
||||
set
|
||||
{
|
||||
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
|
||||
{
|
||||
get { return _Name; }
|
||||
|
||||
set
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
ServiceFacade.DoEmployeeServiceSync(s => _Employee = s.LoadCompactEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value));
|
||||
|
||||
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.TextModulesNurEigeneBearbeiten) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.TextModulesAlleBearbeiten))
|
||||
{
|
||||
_IsOnlyForEmployee = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override TextModuleDC MapToDataContract(TextModuleDC pDataContract, bool doCommit)
|
||||
{
|
||||
pDataContract.Text = _Text;
|
||||
pDataContract.Position = _Position;
|
||||
pDataContract.Name = _Name;
|
||||
pDataContract.IsParent = _IsParent;
|
||||
|
||||
pDataContract.IsOnlyForEmployee = _IsOnlyForEmployee;
|
||||
|
||||
if(_Parent != null)
|
||||
{
|
||||
pDataContract.Parent = _Parent.CommitToDataContract();
|
||||
}
|
||||
|
||||
if(_Employee != null)
|
||||
{
|
||||
pDataContract.Employee = _Employee;
|
||||
}
|
||||
|
||||
if (_ServiceCategory != null)
|
||||
{
|
||||
pDataContract.ServiceCategory = _ServiceCategory;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user