From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ViewModels/Drawer/MetaSeguradoraViewModel.cs | 258 +++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs (limited to 'Codemerx/Gestor.Application/ViewModels/Drawer/MetaSeguradoraViewModel.cs') 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 _metasSeguradora = new ObservableCollection(); + + 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 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 x) => x.get_Id() == this.CancelMetaSeguradora.get_Id())) + { + DomainBase.Copy(this.MetasSeguradora.First((MetaSeguradora x) => x.get_Id() == this.CancelMetaSeguradora.get_Id()), this.CancelMetaSeguradora); + this.SelectedMetaSeguradora = this.MetasSeguradora.First((MetaSeguradora x) => x.get_Id() == this.CancelMetaSeguradora.get_Id()); + } + base.Alterar(false); + this.Carregando = false; + } + + private async Task CarregarMetas(Seguradora seguradora) + { + List metaSeguradoras = await (new BaseServico()).BuscarMetaSeguradoraAsync(seguradora); + MetaSeguradoraViewModel observableCollection = this; + List metaSeguradoras1 = metaSeguradoras; + IOrderedEnumerable mes = + from x in metaSeguradoras1 + orderby x.get_Mes() + select x; + observableCollection.MetasSeguradora = new ObservableCollection(mes.ThenBy((MetaSeguradora x) => x.get_Valor())); + } + + public async Task 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(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(num) : this.MetasSeguradora.Last()); + 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>> Salvar() + { + List> 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 x) => x.get_Id() == metaSeguradora.get_Id())) + { + this.MetasSeguradora.Add(metaSeguradora); + } + else + { + DomainBase.Copy(this.MetasSeguradora.First((MetaSeguradora x) => x.get_Id() == metaSeguradora.get_Id()), metaSeguradora); + } + this.MetasSeguradora = new ObservableCollection(this.MetasSeguradora); + this.SelectedMetaSeguradora = this.MetasSeguradora.First((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()); + } + this.Carregando = false; + } + } +} \ No newline at end of file -- cgit v1.2.3