using System.Collections.Generic; using System.Linq; using BeWo.ServiceProxy; using BeWo.ViewModel; using BS.Shared.DataContracts; using BS.Shared.Extensions; namespace BeWo.View.Detail { public partial class InvoiceNumberView : BeWoView { private IList _Viewmodel; public InvoiceNumberView(IList viewModel) { this.InitializeComponent(); this.ViewModel = viewModel; } public override bool IsDirty { get { return this.ViewModel != null ? this.ViewModel.Any(v => v.IsDirty) : false; } } private IList ViewModel { get { return this._Viewmodel; } set { this.DataContext = value; this._Viewmodel = value; } } protected override void Save() { var dcList = new List(); foreach (var vm in ViewModel) { dcList.Add(vm.CommitToDataContract()); } ServiceFacade.DoAccountingServiceAsync(s => s.UpdateInvoiceNumberList(dcList), this.ReloadViewModel); } private void ReloadViewModel() { ServiceFacade.DoAccountingServiceAsync(s => s.LoadInvoiceNumberList(), r => this.Dispatch(delegate { var vmList = new List(); foreach (var dc in r) { vmList.Add(new InvoiceNumberVM(dc)); } this.ViewModel = vmList; })); } } }