diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs new file mode 100644 index 0000000..71d96c5 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs @@ -0,0 +1,258 @@ +using Assinador.Infrastructure.Helpers;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Common;
+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 MetaSeguradoraViewModel : BaseSegurosViewModel
+ {
+ private readonly MetaSeguradoraServico _servico;
+
+ private readonly Seguradora _selectedSeguradora;
+
+ private MetaSeguradora _selectedMetaSeguradora = new MetaSeguradora();
+
+ private ObservableCollection<MetaSeguradora> _metasSeguradora = new ObservableCollection<MetaSeguradora>();
+
+ private bool _carregando;
+
+ public MetaSeguradora CancelMetaSeguradora;
+
+ public bool Carregando
+ {
+ get
+ {
+ return this._carregando;
+ }
+ set
+ {
+ this._carregando = value;
+ base.IsEnabled = !value;
+ base.EnableMenu = !value;
+ base.OnPropertyChanged("Carregando");
+ }
+ }
+
+ public ObservableCollection<MetaSeguradora> MetasSeguradora
+ {
+ get
+ {
+ return this._metasSeguradora;
+ }
+ set
+ {
+ this._metasSeguradora = value;
+ base.OnPropertyChanged("MetasSeguradora");
+ }
+ }
+
+ public MetaSeguradora SelectedMetaSeguradora
+ {
+ get
+ {
+ return this._selectedMetaSeguradora;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedMetaSeguradora = value;
+ this.CancelMetaSeguradora = (value == null || value.get_Id() <= (long)0 ? this.CancelMetaSeguradora : value);
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ base.OnPropertyChanged("SelectedMetaSeguradora");
+ }
+ }
+
+ public MetaSeguradoraViewModel(Seguradora seguradora)
+ {
+ this._servico = new MetaSeguradoraServico();
+ this.Seleciona(seguradora);
+ this._selectedSeguradora = seguradora;
+ }
+
+ public void CancelarAlteracao()
+ {
+ this.Carregando = true;
+ if (this.CancelMetaSeguradora != null && this.MetasSeguradora.Any<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == this.CancelMetaSeguradora.get_Id()))
+ {
+ DomainBase.Copy<MetaSeguradora, MetaSeguradora>(this.MetasSeguradora.First<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == this.CancelMetaSeguradora.get_Id()), this.CancelMetaSeguradora);
+ this.SelectedMetaSeguradora = this.MetasSeguradora.First<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == this.CancelMetaSeguradora.get_Id());
+ }
+ base.Alterar(false);
+ this.Carregando = false;
+ }
+
+ private async Task CarregarMetas(Seguradora seguradora)
+ {
+ List<MetaSeguradora> metaSeguradoras = await (new BaseServico()).BuscarMetaSeguradoraAsync(seguradora);
+ MetaSeguradoraViewModel observableCollection = this;
+ List<MetaSeguradora> metaSeguradoras1 = metaSeguradoras;
+ IOrderedEnumerable<MetaSeguradora> mes =
+ from x in metaSeguradoras1
+ orderby x.get_Mes()
+ select x;
+ observableCollection.MetasSeguradora = new ObservableCollection<MetaSeguradora>(mes.ThenBy<MetaSeguradora, decimal>((MetaSeguradora x) => x.get_Valor()));
+ }
+
+ public async Task<bool> Excluir()
+ {
+ bool flag;
+ string nome;
+ MetaSeguradora metaSeguradora;
+ if (this.SelectedMetaSeguradora == null || this.SelectedMetaSeguradora.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.SelectedMetaSeguradora))
+ {
+ MetaSeguradoraViewModel metaSeguradoraViewModel = this;
+ Seguradora seguradora = this.SelectedMetaSeguradora.get_Seguradora();
+ if (seguradora != null)
+ {
+ nome = seguradora.get_Nome();
+ }
+ else
+ {
+ nome = null;
+ }
+ string str = string.Concat("EXCLUIU META DA SEGURADORA \"", nome, "\"");
+ long id = this.SelectedMetaSeguradora.get_Id();
+ TipoTela? nullable = new TipoTela?(31);
+ object[] objArray = new object[] { this.SelectedMetaSeguradora.get_Id(), this.SelectedMetaSeguradora.get_Valor(), Functions.GetDescription(this.SelectedMetaSeguradora.get_Mes()), this.SelectedMetaSeguradora.get_Ano() };
+ metaSeguradoraViewModel.RegistrarAcao(str, id, nullable, string.Format("ID: {0}\nVALOR: {1:C}\nMÊS: {2}\nANO: {3}", objArray));
+ int num = this.MetasSeguradora.IndexOf(this.SelectedMetaSeguradora);
+ this.MetasSeguradora.Remove(this.SelectedMetaSeguradora);
+ this.MetasSeguradora.Remove(this.SelectedMetaSeguradora);
+ this.MetasSeguradora = new ObservableCollection<MetaSeguradora>(this.MetasSeguradora);
+ if (this.MetasSeguradora.Count <= 0)
+ {
+ this.SelectedMetaSeguradora = new MetaSeguradora();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ base.EnableAlterar = false;
+ base.EnableExcluir = false;
+ }
+ else
+ {
+ MetaSeguradoraViewModel metaSeguradoraViewModel1 = this;
+ metaSeguradora = (num < this.MetasSeguradora.Count ? this.MetasSeguradora.ElementAt<MetaSeguradora>(num) : this.MetasSeguradora.Last<MetaSeguradora>());
+ metaSeguradoraViewModel1.SelectedMetaSeguradora = metaSeguradora;
+ }
+ this.Carregando = false;
+ flag = true;
+ }
+ else
+ {
+ this.Carregando = false;
+ base.Alterar(false);
+ flag = false;
+ }
+ }
+ else
+ {
+ flag = false;
+ }
+ return flag;
+ }
+
+ public void Incluir()
+ {
+ DateTime date = Funcoes.GetNetworkTime().Date;
+ MetaSeguradora metaSeguradora = new MetaSeguradora();
+ metaSeguradora.set_Ano((long)date.Year);
+ metaSeguradora.set_Mes(date.Month);
+ this.SelectedMetaSeguradora = metaSeguradora;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ this.SelectedMetaSeguradora.set_Seguradora(this._selectedSeguradora);
+ str = (this.SelectedMetaSeguradora.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ string str1 = str;
+ MetaSeguradora metaSeguradora = await this._servico.Save(this.SelectedMetaSeguradora);
+ if (this._servico.Sucesso)
+ {
+ string str2 = string.Concat(str1, " META DA SEGURADORA \"", metaSeguradora.get_Seguradora().get_Nome(), "\"");
+ long id = metaSeguradora.get_Id();
+ TipoTela? nullable = new TipoTela?(31);
+ object[] objArray = new object[] { metaSeguradora.get_Id(), metaSeguradora.get_Valor(), Functions.GetDescription(metaSeguradora.get_Mes()), metaSeguradora.get_Ano() };
+ base.RegistrarAcao(str2, id, nullable, string.Format("ID: {0}\nVALOR: {1:C}\nMÊS: {2}\nANO: {3}", objArray));
+ if (!this.MetasSeguradora.Any<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == metaSeguradora.get_Id()))
+ {
+ this.MetasSeguradora.Add(metaSeguradora);
+ }
+ else
+ {
+ DomainBase.Copy<MetaSeguradora, MetaSeguradora>(this.MetasSeguradora.First<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == metaSeguradora.get_Id()), metaSeguradora);
+ }
+ this.MetasSeguradora = new ObservableCollection<MetaSeguradora>(this.MetasSeguradora);
+ this.SelectedMetaSeguradora = this.MetasSeguradora.First<MetaSeguradora>((MetaSeguradora x) => x.get_Id() == metaSeguradora.get_Id());
+ base.Alterar(false);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ str1 = null;
+ return keyValuePairs;
+ }
+
+ private async void Seleciona(Seguradora seguradora)
+ {
+ base.Loading(true);
+ await base.PermissaoTela(31);
+ await this.SelecionaMetasSeguradora(seguradora);
+ base.Loading(false);
+ }
+
+ public void SelecionaMetaSeguradora(MetaSeguradora metaSeguradora)
+ {
+ this.SelectedMetaSeguradora = metaSeguradora;
+ }
+
+ private async Task SelecionaMetasSeguradora(Seguradora seguradora)
+ {
+ this.Carregando = true;
+ await this.CarregarMetas(seguradora);
+ if (this.MetasSeguradora.Count <= 0)
+ {
+ this.SelectedMetaSeguradora = new MetaSeguradora();
+ base.Alterar(false);
+ base.EnableMenu = false;
+ base.EnableAlterar = false;
+ base.EnableExcluir = false;
+ }
+ else
+ {
+ this.SelecionaMetaSeguradora(this.MetasSeguradora.First<MetaSeguradora>());
+ }
+ this.Carregando = false;
+ }
+ }
+}
\ No newline at end of file |