Files
BeWoPlaner/BeWo/ViewModel/AbsenceReasonVM.cs

182 lines
5.2 KiB
C#
Raw Permalink Normal View History

2016-06-27 01:45:38 +02:00
using System;
using BeWo.Validation;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using System.Windows.Media;
2023-10-26 00:06:56 +02:00
using BS.Shared;
2016-06-27 01:45:38 +02:00
namespace BeWo.ViewModel
{
public class AbsenceReasonVM : AbstractDCMapperVM<AbsenceReasonDC>
{
public static string PropertyName_Brush = "Brush";
public static string PropertyName_Description = "Description";
public static string PropertyName_Hours = "Hours";
public static string PropertyName_IsDeleteable = "IsDeleteable";
public static string PropertyName_Minutes = "Minutes";
2023-10-26 00:06:56 +02:00
public static string PropertyName_Sichtbarkeit = "Sichtbarkeit";
2016-06-27 01:45:38 +02:00
private SolidColorBrush _Brush;
private string _BrushString;
private string _Description;
private int? _Hours;
private bool _IsDeleteable = true;
private int? _Minutes;
2023-10-26 00:06:56 +02:00
private AbsenceReasonVisibilityType? _Sichtbarkeit;
2016-06-27 01:45:38 +02:00
public AbsenceReasonVM(AbsenceReasonDC pDC)
: base(pDC, pDC.AbsenceReasonOid == null) {}
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
public string Description
{
get
{
return this._Description;
}
set
{
if (this.AreDifferent(this._Description, value))
{
this._Description = value;
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Description, value), PropertyName_Description);
this.FirePropertyChanged(PropertyName_Description);
}
}
}
public SolidColorBrush Brush
{
get { return this._Brush; }
set
{
if (this.AreDifferent(this._Brush, value))
{
this._Brush = value;
this._BrushString = value.ToStringNullCheck();
this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Color, value.ToString()), PropertyName_Brush);
this.FirePropertyChanged(PropertyName_Brush);
}
}
}
public int? Hours
{
get
{
return this._Hours;
}
set
{
this._Hours = value;
this.StoreDirtyInformation(true, PropertyName_Hours);
this.FirePropertyChanged(PropertyName_Hours);
}
}
public bool IsDeleteable
{
get
{
return this._IsDeleteable;
}
}
public int? Minutes
{
get
{
return this._Minutes;
}
set
{
this._Minutes = value;
this.StoreDirtyInformation(true, PropertyName_Minutes);
this.FirePropertyChanged(PropertyName_Minutes);
}
}
2023-10-26 00:06:56 +02:00
public AbsenceReasonVisibilityType? Sichtbarkeit
{
get
{
return this._Sichtbarkeit;
}
set
{
this._Sichtbarkeit = value;
this.StoreDirtyInformation(true, PropertyName_Sichtbarkeit);
this.FirePropertyChanged(PropertyName_Sichtbarkeit);
}
}
2016-06-27 01:45:38 +02:00
protected override void InitByDataContract(AbsenceReasonDC pDataContract)
{
if (!this.IsNew)
{
this._Description = pDataContract.Description;
if (pDataContract.BillableMinutes.HasValue)
{
this._Hours = Convert.ToInt32(Math.Floor(pDataContract.BillableMinutes.Value / 60));
this._Minutes = Convert.ToInt32(pDataContract.BillableMinutes.Value % 60);
}
this._IsDeleteable = !pDataContract.IsSystemEntry;
if (!string.IsNullOrEmpty(pDataContract.Color))
{
this.Brush = (SolidColorBrush)new BrushConverter().ConvertFrom(pDataContract.Color);
}
}
2023-10-26 00:06:56 +02:00
this._Sichtbarkeit = pDataContract.Sichtbarkeit ?? AbsenceReasonVisibilityType.All;
2016-06-27 01:45:38 +02:00
}
protected override AbsenceReasonDC MapToDataContract(AbsenceReasonDC pDataContract, bool doCommit)
{
pDataContract.Description = this._Description;
if (this._Hours == null && this._Minutes == null)
{
pDataContract.BillableMinutes = null;
}
else
{
if (this._Hours == null)
{
this._Hours = 0;
}
if (this._Minutes == null)
{
this._Minutes = 0;
}
pDataContract.BillableMinutes = this._Hours * 60 + this._Minutes;
}
pDataContract.Color = this._BrushString;
2023-10-26 00:06:56 +02:00
pDataContract.Sichtbarkeit = this._Sichtbarkeit;
2016-06-27 01:45:38 +02:00
return pDataContract;
}
}
}