using BS.Shared.DataContracts; using System; using System.Collections.Generic; using BeWo.ViewModel.ListViewModel; using BS.Shared.DataContracts.Compact; namespace BeWo.ViewModel { public class ArbeitszeitVM : AbstractDCMapperVM { public static string PropertyName_GueltigVon = "GueltigVon"; public static string PropertyName_GueltigBis = "GueltigBis"; public static string PropertyName_Notice = "Notice"; public static string PropertyName_ArbeitszeitEintragListeVM = "ArbeitszeitEintragListeVM"; public static string PropertyName_ArbeitszeitString = "ArbeitszeitString"; public static string PropertyName_CompactCustomer = "CompactCustomer"; public static string PropertyName_Klient = "Klient"; private CompactCustomerDC _Customer; private DateTime? _GueltigVon; private DateTime? _GueltigBis; private string _Notice; private ArbeitszeitEintragListVM _ArbeitszeitEintraege; public ArbeitszeitVM(ArbeitszeitDC pDC) : base(pDC, pDC.ArbeitszeitOid == null) { } public override bool IsDirty => base.IsDirty || ArbeitszeitEintraege != null && ArbeitszeitEintraege.IsDirty; public CompactCustomerDC Customer { get => _Customer; set { if(AreDifferent(_Customer, value)) { _Customer = value; StoreDirtyInformation(AreDifferent(DataContract.Customer, value), nameof(Customer)); FirePropertyChanged(nameof(Customer)); } } } public DateTime? GueltigVon { get => _GueltigVon; set { if(AreDifferent(_GueltigVon, value)) { _GueltigVon = value; StoreDirtyInformation(AreDifferent(DataContract.GueltigVon, value), nameof(GueltigVon)); FirePropertyChanged(nameof(GueltigVon)); FirePropertyChanged(nameof(ArbeitszeitString)); } } } public DateTime? GueltigBis { get => _GueltigBis; set { if(AreDifferent(_GueltigBis, value)) { _GueltigBis = value; StoreDirtyInformation(AreDifferent(DataContract.GueltigBis, value), nameof(GueltigBis)); FirePropertyChanged(nameof(GueltigBis)); FirePropertyChanged(nameof(ArbeitszeitString)); } } } public string Notice { get => _Notice; set { if(AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Notice, value), nameof(Notice)); FirePropertyChanged(nameof(Notice)); } } } public string ArbeitszeitString { get { var text = "Zeitraum: "; if(_GueltigVon.HasValue) { text = $"{_GueltigVon:dd.MM.yyyy}"; if(_GueltigBis.HasValue) { text += $" - {_GueltigBis:dd.MM.yyyy}"; } } else { if(_GueltigBis.HasValue) { text = $"bis {_GueltigBis:dd.MM.yyyy}"; } } if(string.IsNullOrEmpty(text)) { //if (this.IsNew) text = ""; //else // text = "Arbeitszeitplanung"; } return text; } } public ArbeitszeitEintragListVM ArbeitszeitEintraege { get => _ArbeitszeitEintraege; set { _ArbeitszeitEintraege = value; FirePropertyChanged(nameof(ArbeitszeitEintraege)); } } protected override void InitByDataContract(ArbeitszeitDC pDataContract) { _GueltigBis = pDataContract.GueltigBis; _GueltigVon = pDataContract.GueltigVon; _Notice = pDataContract.Notice; _Customer = pDataContract.Customer; ArbeitszeitEintraege = VMFactory.CreateArbeitszeitEintragListVm(pDataContract.Eintraege ?? (pDataContract.Eintraege = new List())); } protected override ArbeitszeitDC MapToDataContract(ArbeitszeitDC pDataContract, bool doCommit) { pDataContract.GueltigVon = _GueltigVon; pDataContract.GueltigBis = _GueltigBis; pDataContract.Notice = _Notice; pDataContract.Customer = _Customer; pDataContract.Eintraege = ArbeitszeitEintraege.CopyToDCList(doCommit); return pDataContract; } } }