Files
BeWoPlaner/BeWo/ViewModel/AddressVM.cs
2025-05-26 11:36:48 +02:00

150 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BS.Shared.DataContracts;
namespace BeWo.ViewModel
{
public class AddressVM : AbstractDCMapperVM<AddressDC>
{
private string _AddressLine1;
private string _AddressLine2;
private string _Country;
private long? _L_Version;
private decimal? _Latitude;
private decimal? _Longitude;
private string _PostalCode;
private string _State;
private string _Street;
private string _Town;
public AddressVM() : this(new AddressDC()) { }
public AddressVM(AddressDC dc) : base(dc, dc.Oid)
{
}
public string AddressLine1
{
get => _AddressLine1;
set => SetProperty(ref _AddressLine1, value, nameof(AddressLine1), () => DataContract.AddressLine1);
}
public string AddressLine2
{
get => _AddressLine2;
set => SetProperty(ref _AddressLine2, value, nameof(AddressLine2), () => DataContract.AddressLine2);
}
public string Country
{
get => _Country;
set => SetProperty(ref _Country, value, nameof(Country), () => DataContract.Country);
}
public long? L_Version
{
get => _L_Version;
set => SetProperty(ref _L_Version, value, nameof(L_Version), () => DataContract.L_Version);
}
public decimal? Latitude
{
get => _Latitude;
set => SetProperty(ref _Latitude, value, nameof(Latitude), () => DataContract.Latitude);
}
public decimal? Longitude
{
get => _Longitude;
set => SetProperty(ref _Longitude, value, nameof(Longitude), () => DataContract.Longitude);
}
public string PostalCode
{
get => _PostalCode;
set => SetProperty(ref _PostalCode, value, nameof(PostalCode), () => DataContract.PostalCode);
}
public string State
{
get => _State;
set => SetProperty(ref _State, value, nameof(State), () => DataContract.State);
}
public string Street
{
get => _Street;
set => SetProperty(ref _Street, value, nameof(Street), () => DataContract.Street);
}
public string Town
{
get => _Town;
set => SetProperty(ref _Town, value, nameof(Town), () => DataContract.Town);
}
protected override void InitByDataContract(AddressDC pDataContract)
{
_AddressLine1 = pDataContract.AddressLine1;
_AddressLine2 = pDataContract.AddressLine2;
_Country = pDataContract.Country;
_L_Version = pDataContract.L_Version;
_Latitude = pDataContract.Latitude;
_Longitude = pDataContract.Longitude;
_PostalCode = pDataContract.PostalCode;
_State = pDataContract.State;
_Street = pDataContract.Street;
_Town = pDataContract.Town;
}
protected override AddressDC MapToDataContract(AddressDC pDataContract, bool doCommit)
{
pDataContract.AddressLine1 = _AddressLine1;
pDataContract.AddressLine2 = _AddressLine2;
pDataContract.Country = _Country;
pDataContract.L_Version = _L_Version;
pDataContract.Latitude = _Latitude;
pDataContract.Longitude = _Longitude;
pDataContract.PostalCode = _PostalCode;
pDataContract.State = _State;
pDataContract.Street = _Street;
pDataContract.Town = _Town;
return pDataContract;
}
public string ToSingleLine()
{
var parts = new List<string>
{
AddressLine1,
AddressLine2,
Street,
PostalCode,
Town,
State,
Country
};
return string.Join(", ", parts.Where(p => !string.IsNullOrWhiteSpace(p)));
}
public override void UpdateByDataContract(AddressDC pDataContract)
{
AddressLine1 = pDataContract.AddressLine1;
AddressLine2 = pDataContract.AddressLine2;
Country = pDataContract.Country;
L_Version = pDataContract.L_Version;
Latitude = pDataContract.Latitude;
Longitude = pDataContract.Longitude;
PostalCode = pDataContract.PostalCode;
State = pDataContract.State;
Street = pDataContract.Street;
Town = pDataContract.Town;
FirePropertyChangedItself();
}
}
}