diff options
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels/CoberturaViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels/CoberturaViewModel.cs | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels/CoberturaViewModel.cs b/Decompiler/Gestor.Application.ViewModels/CoberturaViewModel.cs new file mode 100644 index 0000000..47f386d --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels/CoberturaViewModel.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Seguros.Itens; +using Gestor.Application.ViewModels.Generic; +using Gestor.Application.ViewModels.Seguros; +using Gestor.Common.Validation; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels; + +public class CoberturaViewModel : BaseSegurosViewModel +{ + private readonly ItemServico _itemServico; + + private Cobertura _selectedCobertura = new Cobertura(); + + private List<CoberturaPadrao> _coberturasPadrao; + + private ObservableCollection<Cobertura> _coberturas; + + private readonly IComparer<Cobertura> _comparerCobertura = Comparer<Cobertura>.Create(delegate(Cobertura item1, Cobertura item2) + { + if (((DomainBase)item1).Id > ((DomainBase)item2).Id) + { + return 1; + } + return (((DomainBase)item1).Id < ((DomainBase)item2).Id) ? (-1) : 0; + }); + + public Item Item { get; set; } + + public Ramo Ramo { get; set; } + + public Cobertura SelectedCobertura + { + get + { + return _selectedCobertura; + } + set + { + _selectedCobertura = value; + OnPropertyChanged("SelectedCobertura"); + } + } + + public List<CoberturaPadrao> CoberturasPadrao + { + get + { + return _coberturasPadrao; + } + set + { + _coberturasPadrao = value; + OnPropertyChanged("CoberturasPadrao"); + } + } + + public ObservableCollection<Cobertura> Coberturas + { + get + { + return _coberturas; + } + set + { + _coberturas = value; + OnPropertyChanged("Coberturas"); + } + } + + public CoberturaViewModel(Ramo ramo = null, Item item = null) + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + Item = item ?? ConsultaViewModel.ItemSelecionado; + object obj = ramo; + if (obj == null) + { + Documento documentoSelecionado = ConsultaViewModel.DocumentoSelecionado; + if (documentoSelecionado == null) + { + obj = null; + } + else + { + Controle controle = documentoSelecionado.Controle; + obj = ((controle != null) ? controle.Ramo : null); + } + } + Ramo = (Ramo)obj; + _itemServico = new ItemServico(); + } + + public async Task SelectionaCoberturas() + { + if (Ramo != null) + { + CoberturasPadrao = Recursos.Coberturas.Where((CoberturaPadrao x) => x.IdRamo == ((DomainBase)Ramo).Id).ToList(); + if (Item != null) + { + Coberturas = await _itemServico.BuscarCoberturasPorItemAsync(((DomainBase)Item).Id); + } + } + } + + internal async Task<List<CoberturaPadrao>> BuscarCobertura(string value) + { + return await Task.Run(() => CoberturasPadrao?.Where((CoberturaPadrao x) => ValidationHelper.RemoveDiacritics(x.Descricao.ToUpper().Trim()).Contains(value.ToUpper())).ToList()); + } + + public void AdicionaCobertura() + { + //IL_0000: Unknown result type (might be due to invalid IL or missing references) + //IL_0005: Unknown result type (might be due to invalid IL or missing references) + //IL_0012: Expected O, but got Unknown + Cobertura val = new Cobertura + { + Item = Item + }; + ValidationHelper.AddSorted<Cobertura>(Coberturas, val, _comparerCobertura); + SelectedCobertura = val; + } + + public async void ExcluirCobertura(Cobertura cobertura) + { + if (cobertura != null && await ShowMessage("DESEJA REALMENTE EXCLUIR A COBERTURA" + Environment.NewLine + "\"" + cobertura.Observacao + "\"?", "SIM", "NÃO")) + { + Coberturas.Remove(cobertura); + } + } + + public async Task<IList<Cobertura>> LimpaCoberturas() + { + bool flag = Coberturas != null && Coberturas.Any((Cobertura x) => x.Franquia == 0m && x.Lmi == 0m && x.Premio == 0m); + if (flag) + { + flag = await ShowMessage("DESEJA LIMPAR AS COBERTURAS SEM VALOR DE FRANQUIA, LMI E PRÊMIO?", "SIM", "NÃO"); + } + return (!flag) ? Coberturas?.ToList() : Coberturas?.Where((Cobertura x) => !string.IsNullOrEmpty(x.Observacao) && (x.Franquia != 0m || x.Lmi != 0m || x.Premio != 0m)).ToList(); + } + + public async Task CancelarAlteracao() + { + if (Item != null) + { + Coberturas = await _itemServico.BuscarCoberturasPorItemAsync(((DomainBase)Item).Id); + } + } + + public void CarregaPadrao() + { + List<Cobertura> list = CoberturasPadrao?.Where((CoberturaPadrao x) => x.Padrao).Select((Func<CoberturaPadrao, Cobertura>)((CoberturaPadrao x) => new Cobertura + { + CoberturaPadrao = x, + Observacao = x.Descricao + })).ToList(); + if (list != null) + { + Coberturas = new ObservableCollection<Cobertura>(list); + } + } + + public ObservableCollection<Cobertura> CarregaCoberturaPadrao() + { + List<Cobertura> list = CoberturasPadrao?.Where((CoberturaPadrao x) => x.Padrao).Select((Func<CoberturaPadrao, Cobertura>)((CoberturaPadrao x) => new Cobertura + { + CoberturaPadrao = x, + Observacao = x.Descricao + })).ToList(); + return Coberturas = new ObservableCollection<Cobertura>(list); + } +} |