using BeWo.Validation; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; namespace BeWo.ViewModel { public class CustomerPersonRelationVM : AbstractDCMapperVM { public static string PropertyName_Notice = "Notice"; public static string PropertyName_Person = "Person"; public static string PropertyName_Organisation = "Organisation"; public static string PropertyName_PersonString = "PersonString"; public static string PropertyName_OrganisationString = "OrganisationString"; public static string PropertyName_AddressSummaryInfo = "AddressSummaryInfo"; public static string PropertyName_ContactSummaryInfo = "ContactSummaryInfo"; public static string PropertyName_Role = "Role"; public static string PropertyName_IstFamilie = "IstFamilie"; private string _Notice; private CompactPersonDC _Person; private CompactOrganisationDC _Organisation; private ValueListEntryDC _Role; private bool _IstFamilie; public CustomerPersonRelationVM(CustomerPersonRelationDC pDC) : base(pDC, pDC.Customer2PersonOid == null) { } public bool IstFamilie { get { return _IstFamilie; } set { if (AreDifferent(_IstFamilie, value)) { _IstFamilie = value; StoreDirtyInformation(AreDifferent(DataContract.IstFamilie, value), PropertyName_IstFamilie); FirePropertyChanged(PropertyName_IstFamilie); } } } public string Notice { get { return _Notice; } set { if (AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Customer2PersonNotice, value), PropertyName_Notice); FirePropertyChanged(PropertyName_Notice); } } } public CompactPersonDC Person { get { return _Person; } set { if (AreDifferent(_Person, value)) { _Person = value; StoreDirtyInformation(AreDifferent(DataContract.Person, value), PropertyName_Person); FirePropertyChanged(PropertyName_Person); FirePropertyChanged(PropertyName_PersonString); FirePropertyChanged(PropertyName_AddressSummaryInfo); FirePropertyChanged(PropertyName_ContactSummaryInfo); } } } public CompactOrganisationDC Organisation { get { return _Organisation; } set { if (AreDifferent(_Organisation, value)) { _Organisation = value; StoreDirtyInformation(AreDifferent(DataContract.Organisation, value), PropertyName_Organisation); FirePropertyChanged(PropertyName_Organisation); FirePropertyChanged(PropertyName_OrganisationString); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public string PersonString { get { return _Person.ToStringNullCheck(); } // Validation Workaround set { } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public string OrganisationString { get { return _Organisation.ToStringNullCheck(); } // Validation Workaround set { } } public string AddressSummaryInfo { get { var address = _Person.Street; if (!string.IsNullOrEmpty(address)) { address += "\n"; } if (address == null) { address = string.Empty; } address += _Person.PostalCode + " " + _Person.Town; return address; } set { } } public string ContactSummaryInfo { get { var info = string.Empty; if (!string.IsNullOrEmpty(_Person.Communication1)) { info = "Tel.: " + _Person.Communication1; } if (!string.IsNullOrEmpty(_Person.Communication2)) { if (info.Length > 0) { info += "\n"; } info += "Mobil: " + _Person.Communication2; } if (!string.IsNullOrEmpty(_Person.Communication3)) { if (info.Length > 0) { info += "\n"; } info += "E-Mail: " + _Person.Communication3; } if (!string.IsNullOrEmpty(_Person.Communication4)) { if (info.Length > 0) { info += "\n"; } info += "Fax: " + _Person.Communication4; } return info; } set { } } [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public ValueListEntryDC Role { get { return _Role; } set { if (AreDifferent(_Role, value)) { _Role = value; StoreDirtyInformation(AreDifferent(DataContract.RelationRole, value), PropertyName_Role); FirePropertyChanged(PropertyName_Role); } } } public string FamilyStatus { get { if (_Person.FamilyStatus.HasValue) { return EnumTranslations.FamilyStatusTranslations[_Person.FamilyStatus]; } return ""; } set { } } protected override void InitByDataContract(CustomerPersonRelationDC pDataContract) { if (!IsNew) { _Notice = pDataContract.Customer2PersonNotice; _Person = pDataContract.Person; _Role = pDataContract.RelationRole; _Organisation = pDataContract.Organisation; _IstFamilie = pDataContract.IstFamilie; } } protected override CustomerPersonRelationDC MapToDataContract(CustomerPersonRelationDC pDataContract, bool doCommit) { pDataContract.Customer2PersonNotice = _Notice; pDataContract.Person = _Person; pDataContract.RelationRole = _Role; pDataContract.Organisation = _Organisation; pDataContract.IstFamilie = _IstFamilie; return pDataContract; } } }