summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Seguros/TrocarClienteViewModel.cs
blob: 2384db15a224cac52c7c2c6963b8c9773724c65c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
	}
}