diff options
Diffstat (limited to 'Gestor.Application/ViewModels/Drawer/ExpedicaoViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Drawer/ExpedicaoViewModel.cs | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/Drawer/ExpedicaoViewModel.cs b/Gestor.Application/ViewModels/Drawer/ExpedicaoViewModel.cs new file mode 100644 index 0000000..2aff10f --- /dev/null +++ b/Gestor.Application/ViewModels/Drawer/ExpedicaoViewModel.cs @@ -0,0 +1,196 @@ +using Gestor.Application.Servicos.Generic;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.ViewModels.Drawer
+{
+ public class ExpedicaoViewModel : BaseSegurosViewModel
+ {
+ private readonly ExpedicaoServico _servico;
+
+ private readonly Documento _documento;
+
+ private bool _carregando;
+
+ private Expedicao _selectedExpedicao = new Expedicao();
+
+ private ObservableCollection<Expedicao> _expedicoes = new ObservableCollection<Expedicao>();
+
+ public bool Carregando
+ {
+ get
+ {
+ return this._carregando;
+ }
+ set
+ {
+ this._carregando = value;
+ base.EnableMenu = !value;
+ base.OnPropertyChanged("Carregando");
+ }
+ }
+
+ public ObservableCollection<Expedicao> Expedicoes
+ {
+ get
+ {
+ return this._expedicoes;
+ }
+ set
+ {
+ this._expedicoes = value;
+ base.OnPropertyChanged("Expedicoes");
+ }
+ }
+
+ public Expedicao SelectedExpedicao
+ {
+ get
+ {
+ return this._selectedExpedicao;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedExpedicao = value;
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ base.OnPropertyChanged("SelectedExpedicao");
+ }
+ }
+
+ public ExpedicaoViewModel(Documento documento)
+ {
+ this._servico = new ExpedicaoServico();
+ this._documento = documento;
+ this.Seleciona(documento);
+ }
+
+ public async void CancelarAlteracao()
+ {
+ Expedicao expedicao;
+ this.Carregando = true;
+ long id = this.SelectedExpedicao.get_Id();
+ await this.Carregar(this.SelectedExpedicao.get_Apolice());
+ ExpedicaoViewModel expedicaoViewModel = this;
+ if (this.Expedicoes.Count <= 0 || id <= (long)0)
+ {
+ expedicao = (this.Expedicoes.Count <= 0 || id != 0 ? new Expedicao() : this.Expedicoes.First<Expedicao>());
+ }
+ else
+ {
+ expedicao = this.Expedicoes.FirstOrDefault<Expedicao>((Expedicao x) => x.get_Id() == id);
+ }
+ expedicaoViewModel.SelectedExpedicao = expedicao;
+ base.Alterar(false);
+ this.Carregando = false;
+ }
+
+ private async Task Carregar(Documento documento)
+ {
+ this.Expedicoes = new ObservableCollection<Expedicao>(await this._servico.BuscarExpedicoes(documento));
+ }
+
+ public async Task<bool> Excluir()
+ {
+ bool flag;
+ Expedicao expedicao;
+ if (this.SelectedExpedicao == null || this.SelectedExpedicao.get_Id() == 0)
+ {
+ flag = false;
+ }
+ else if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false))
+ {
+ this.Carregando = true;
+ if (await this._servico.Delete(this.SelectedExpedicao))
+ {
+ int num = this.Expedicoes.IndexOf(this.SelectedExpedicao);
+ this.Expedicoes.Remove(this.SelectedExpedicao);
+ if (this.Expedicoes.Count <= 0)
+ {
+ this.SelectedExpedicao = new Expedicao();
+ }
+ else
+ {
+ ExpedicaoViewModel expedicaoViewModel = this;
+ expedicao = (num < this.Expedicoes.Count ? this.Expedicoes.ElementAt<Expedicao>(num) : this.Expedicoes.Last<Expedicao>());
+ expedicaoViewModel.SelectedExpedicao = expedicao;
+ }
+ this.Carregando = false;
+ flag = true;
+ }
+ else
+ {
+ this.Carregando = false;
+ flag = false;
+ }
+ }
+ else
+ {
+ flag = false;
+ }
+ return flag;
+ }
+
+ public void Incluir()
+ {
+ Expedicao expedicao = new Expedicao();
+ expedicao.set_Apolice(this._documento);
+ this.SelectedExpedicao = expedicao;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ this.SelectedExpedicao = await this._servico.Save(this.SelectedExpedicao);
+ if (this._servico.Sucesso)
+ {
+ long id = this.SelectedExpedicao.get_Id();
+ await this.Carregar(this.SelectedExpedicao.get_Apolice());
+ this.SelectedExpedicao = this.Expedicoes.FirstOrDefault<Expedicao>((Expedicao x) => x.get_Id() == id);
+ base.Alterar(false);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ return keyValuePairs;
+ }
+
+ private async void Seleciona(Documento documento)
+ {
+ this.Carregando = true;
+ await base.PermissaoTela(46);
+ await this.Carregar(documento);
+ if (this.Expedicoes.Count <= 0)
+ {
+ this.SelectedExpedicao = new Expedicao();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ }
+ else
+ {
+ this.SelectedExpedicao = this.Expedicoes.First<Expedicao>();
+ }
+ this.Carregando = false;
+ }
+ }
+}
\ No newline at end of file |