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 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; } }