using System.Collections.ObjectModel; using System.Linq; using BeWo.Validation; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; namespace BeWo.ViewModel { public class GroupOfPeopleVM : AbstractDCMapperVM { public static string PropertyName_EmployeeList = "EmployeeList"; public static string PropertyName_SupportConceptList = "SupportConceptList"; public static string PropertyName_CustomerList = "CustomerList"; public static string PropertyName_Name = "Name"; private ObservableCollection _EmployeeList; private ObservableCollection _SupportConceptList; private ObservableCollection _CustomerList; private string _Name; private long _CreatedByEmployeeOid; public GroupOfPeopleVM(GroupOfPeopleDC pDataContract) : base(pDataContract, pDataContract.GroupOfPeopleOid == null) { } public ObservableCollection EmployeeList { get { return this._EmployeeList; } set { if (this.AreDifferent(this._EmployeeList, value)) { this._EmployeeList = value; this.FirePropertyChanged(PropertyName_EmployeeList); } } } public ObservableCollection SupportConceptList { get { return this._SupportConceptList; } set { if (this.AreDifferent(this._SupportConceptList, value)) { this._SupportConceptList = value; this.FirePropertyChanged(PropertyName_SupportConceptList); } } } public ObservableCollection CustomerList { get { return this._CustomerList; } set { if (this.AreDifferent(this._CustomerList, value)) { this._CustomerList = value; this.FirePropertyChanged(PropertyName_CustomerList); } } } [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public string Name { get { return this._Name; } set { if (this.AreDifferent(this._Name, value)) { this._Name = value; this.StoreDirtyInformation(this.DataContract.Name != value, PropertyName_Name); this.FirePropertyChanged(PropertyName_Name); } } } public long CreatedByEmployeeOid { get { return this._CreatedByEmployeeOid; } set { this._CreatedByEmployeeOid = value; } } protected override void InitByDataContract(GroupOfPeopleDC pDataContract) { this._EmployeeList = new ObservableCollection(); this._CustomerList = new ObservableCollection(); this._SupportConceptList = new ObservableCollection(); if (!this.IsNew) { this._Name = pDataContract.Name; this._CreatedByEmployeeOid = pDataContract.CreatedByEmployeeOid; if (pDataContract.EmployeeList != null) { this._EmployeeList.AddRange(pDataContract.EmployeeList); } if (pDataContract.SupportConceptList != null) { this._SupportConceptList.AddRange(pDataContract.SupportConceptList); } if (pDataContract.CustomerList != null) { this._CustomerList.AddRange(pDataContract.CustomerList); } } this._EmployeeList.CollectionChanged += (s, e) => this.StoreDirtyInformation(!pDataContract.EmployeeList.ContainsSameItemsAs(this._EmployeeList), PropertyName_EmployeeList); this._CustomerList.CollectionChanged += (s, e) => this.StoreDirtyInformation(!pDataContract.CustomerList.ContainsSameItemsAs(this._CustomerList), PropertyName_CustomerList); this._SupportConceptList.CollectionChanged += (s, e) => this.StoreDirtyInformation(!pDataContract.SupportConceptList.ContainsSameItemsAs(this._SupportConceptList), PropertyName_SupportConceptList); } protected override GroupOfPeopleDC MapToDataContract(GroupOfPeopleDC pDataContract, bool doCommit) { pDataContract.Name = this._Name; pDataContract.CreatedByEmployeeOid = this._CreatedByEmployeeOid; pDataContract.SupportConceptList = this._SupportConceptList.ToList(); pDataContract.CustomerList = this._CustomerList.ToList(); pDataContract.EmployeeList = this._EmployeeList.ToList(); return pDataContract; } public override string ToString() { return this.Name; } } }