summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs
new file mode 100644
index 0000000..2384db1
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs
@@ -0,0 +1,75 @@
+using System.Threading.Tasks;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+
+namespace Gestor.Application.ViewModels.Seguros;
+
+public class TrocarClienteViewModel : BaseSegurosViewModel
+{
+ private readonly ApoliceServico _apoliceServico;
+
+ private readonly ClienteServico _clienteServico;
+
+ private Documento _selectedDocumento;
+
+ private Cliente _selectedCliente;
+
+ public Documento SelectedDocumento
+ {
+ get
+ {
+ return _selectedDocumento;
+ }
+ set
+ {
+ OnPropertyChanged("SelectedDocumento");
+ _selectedDocumento = value;
+ }
+ }
+
+ public Cliente SelectedCliente
+ {
+ get
+ {
+ return _selectedCliente;
+ }
+ set
+ {
+ OnPropertyChanged("SelectedCliente");
+ _selectedCliente = value;
+ }
+ }
+
+ public TrocarClienteViewModel()
+ {
+ _apoliceServico = new ApoliceServico();
+ _clienteServico = new ClienteServico();
+ }
+
+ public async Task<bool> Salvar()
+ {
+ if (SelectedCliente == null)
+ {
+ return false;
+ }
+ if (((DomainBase)SelectedCliente).Id == ((DomainBase)SelectedDocumento.Controle.Cliente).Id)
+ {
+ return false;
+ }
+ Cliente clienteantigo = await _clienteServico.BuscarCliente(((DomainBase)SelectedDocumento.Controle.Cliente).Id);
+ Documento documento = SelectedDocumento;
+ _apoliceServico.Sucesso = true;
+ await _apoliceServico.Save(documento.Controle, SelectedCliente);
+ if (!_apoliceServico.Sucesso)
+ {
+ return false;
+ }
+ RegistrarAcao($"TROCOU O CLIENTE DO DOCUMENTO DE ID {((DomainBase)SelectedDocumento).Id}", ((DomainBase)SelectedDocumento).Id, (TipoTela)41, $"CLIENTE ANTIGO: {clienteantigo.Nome}\nNOVO CLIENTE: {SelectedCliente.Nome} ({((DomainBase)SelectedCliente).Id})");
+ SelectedCliente = documento.Controle.Cliente;
+ SelectedDocumento = documento;
+ return true;
+ }
+}