Files
BeWoPlaner/BeWo/View/Detail/InvoiceNumberView.xaml.cs
2020-08-20 18:35:33 +02:00

66 lines
1.8 KiB
C#

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<InvoiceNumberVM> _Viewmodel;
public InvoiceNumberView(IList<InvoiceNumberVM> viewModel)
{
this.InitializeComponent();
this.ViewModel = viewModel;
}
public override bool IsDirty
{
get
{
return this.ViewModel != null ? this.ViewModel.Any(v => v.IsDirty) : false;
}
}
private IList<InvoiceNumberVM> ViewModel
{
get
{
return this._Viewmodel;
}
set
{
this.DataContext = value;
this._Viewmodel = value;
}
}
protected override void Save()
{
var dcList = new List<InvoiceNumberDC>();
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<InvoiceNumberVM>();
foreach (var dc in r)
{
vmList.Add(new InvoiceNumberVM(dc));
}
this.ViewModel = vmList;
}));
}
}
}