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/BI/NotasViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs')
| -rw-r--r-- | Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs | 311 |
1 files changed, 311 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs b/Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs new file mode 100644 index 0000000..dca2d31 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs @@ -0,0 +1,311 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Ferramentas;
+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.BI
+{
+ public class NotasViewModel : BaseSegurosViewModel
+ {
+ private readonly TarefaServico _servico;
+
+ private bool _enableIncluirNota = true;
+
+ private bool _ocultarUsuarios;
+
+ private ObservableCollection<Usuario> _usuarios;
+
+ private Usuario _selectedUsuario;
+
+ private Gestor.Model.Domain.Ferramentas.Tarefa _tarefa;
+
+ private ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa> _notas;
+
+ private ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa> _notasConcluidas;
+
+ private Gestor.Model.Domain.Ferramentas.Tarefa _selectedNota;
+
+ private bool _ocultarNotasConcluidas = true;
+
+ public bool EnableIncluirNota
+ {
+ get
+ {
+ return this._enableIncluirNota;
+ }
+ set
+ {
+ this._enableIncluirNota = value;
+ base.OnPropertyChanged("EnableIncluirNota");
+ }
+ }
+
+ public ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa> Notas
+ {
+ get
+ {
+ return this._notas;
+ }
+ set
+ {
+ this._notas = value;
+ base.OnPropertyChanged("Notas");
+ }
+ }
+
+ public ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa> NotasConcluidas
+ {
+ get
+ {
+ return this._notasConcluidas;
+ }
+ set
+ {
+ this._notasConcluidas = value;
+ base.OnPropertyChanged("NotasConcluidas");
+ }
+ }
+
+ public bool OcultarNotasConcluidas
+ {
+ get
+ {
+ return this._ocultarNotasConcluidas;
+ }
+ set
+ {
+ this._ocultarNotasConcluidas = value;
+ base.OnPropertyChanged("OcultarNotasConcluidas");
+ }
+ }
+
+ public bool OcultarUsuarios
+ {
+ get
+ {
+ return this._ocultarUsuarios;
+ }
+ set
+ {
+ this._ocultarUsuarios = value;
+ base.OnPropertyChanged("OcultarUsuarios");
+ }
+ }
+
+ public Gestor.Model.Domain.Ferramentas.Tarefa SelectedNota
+ {
+ get
+ {
+ return this._selectedNota;
+ }
+ set
+ {
+ this._selectedNota = value;
+ base.OnPropertyChanged("SelectedNota");
+ }
+ }
+
+ public Usuario SelectedUsuario
+ {
+ get
+ {
+ return this._selectedUsuario;
+ }
+ set
+ {
+ this._selectedUsuario = value;
+ this.Carregar();
+ base.OnPropertyChanged("SelectedUsuario");
+ }
+ }
+
+ public Gestor.Model.Domain.Ferramentas.Tarefa Tarefa
+ {
+ get
+ {
+ return this._tarefa;
+ }
+ set
+ {
+ this._tarefa = value;
+ base.OnPropertyChanged("Tarefa");
+ }
+ }
+
+ public ObservableCollection<Usuario> Usuarios
+ {
+ get
+ {
+ return this._usuarios;
+ }
+ set
+ {
+ this._usuarios = value;
+ base.OnPropertyChanged("Usuarios");
+ }
+ }
+
+ public NotasViewModel()
+ {
+ bool administrador;
+ bool id;
+ this._servico = new TarefaServico();
+ this.Usuarios = new ObservableCollection<Usuario>(Recursos.Usuarios.Where<Usuario>((Usuario x) => {
+ if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa())
+ {
+ return false;
+ }
+ return !x.get_Excluido();
+ }).OrderBy<Usuario, string>((Usuario x) => x.get_Nome()).ToList<Usuario>());
+ this.SelectedUsuario = this.Usuarios.FirstOrDefault<Usuario>((Usuario x) => x.get_Id() == Recursos.Usuario.get_Id());
+ Usuario usuario = Recursos.Usuario;
+ if (usuario != null)
+ {
+ administrador = usuario.get_Administrador();
+ }
+ else
+ {
+ administrador = false;
+ }
+ this.OcultarUsuarios = administrador;
+ Usuario usuario1 = Recursos.Usuario;
+ if (usuario1 != null)
+ {
+ id = usuario1.get_Id() > (long)0;
+ }
+ else
+ {
+ id = false;
+ }
+ this.EnableIncluirNota = id;
+ }
+
+ public async Task AdicionarNota()
+ {
+ Gestor.Model.Domain.Ferramentas.Tarefa tarefa;
+ if (this.Notas != null)
+ {
+ ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa> notas = this.Notas;
+ if (notas.Any<Gestor.Model.Domain.Ferramentas.Tarefa>((Gestor.Model.Domain.Ferramentas.Tarefa x) => {
+ if (x.get_Titulo() != "TÍTULO")
+ {
+ return false;
+ }
+ return x.get_Descricao() == "DESCRIÇÃO";
+ }))
+ {
+ await base.ShowMessage("PARA ADICIONAR OUTRA NOTA, INSERIR TÍTULO E DESCRIÇÃO DA NOTA JÁ ADICIONADA", "OK", "", false);
+ tarefa = null;
+ return;
+ }
+ }
+ Gestor.Model.Domain.Ferramentas.Tarefa tarefa1 = new Gestor.Model.Domain.Ferramentas.Tarefa();
+ tarefa1.set_Agendamento(Funcoes.GetNetworkTime());
+ tarefa1.set_Titulo("TÍTULO");
+ tarefa1.set_Anotacoes("DESCRIÇÃO");
+ tarefa1.set_Usuario(this.Usuarios.First<Usuario>((Usuario x) => x.get_Id() == this.SelectedUsuario.get_Id()));
+ tarefa1.set_UsuarioCadastro(Recursos.Usuario);
+ tarefa1.set_Entidade(1);
+ tarefa1.set_Status(0);
+ tarefa = tarefa1;
+ tarefa = await this._servico.Salvar(tarefa);
+ await this.CarregarNotas();
+ this.SelectedNota = tarefa;
+ tarefa = null;
+ }
+
+ public async void Carregar()
+ {
+ await this.CarregarNotas();
+ }
+
+ public async Task CarregarNotas()
+ {
+ if (this.SelectedUsuario != null)
+ {
+ List<Gestor.Model.Domain.Ferramentas.Tarefa> tarefas = await this._servico.BuscarNotas(this.SelectedUsuario.get_Id());
+ List<Gestor.Model.Domain.Ferramentas.Tarefa> tarefas1 = tarefas;
+ tarefas1.ForEach((Gestor.Model.Domain.Ferramentas.Tarefa x) => {
+ if (x.get_Titulo() == "TÍTULO" && x.get_Descricao() == "DESCRIÇÃO")
+ {
+ x.set_HabilitarPublica(true);
+ }
+ });
+ this.Notas = new ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa>(tarefas);
+ this.NotasConcluidas = new ObservableCollection<Gestor.Model.Domain.Ferramentas.Tarefa>(await this._servico.BuscarNotasConcluidas(this.SelectedUsuario.get_Id()));
+ }
+ }
+
+ public async Task ExcluirNota(Gestor.Model.Domain.Ferramentas.Tarefa nota)
+ {
+ await this._servico.Excluir(nota.get_Id());
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar(Gestor.Model.Domain.Ferramentas.Tarefa destino)
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ Gestor.Model.Domain.Ferramentas.Tarefa tarefa = destino;
+ List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
+ tarefa.set_AgendamentoRetroativo(configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 45));
+ List<KeyValuePair<string, string>> keyValuePairs1 = destino.Validate();
+ if (keyValuePairs1.Count <= 0)
+ {
+ bool publica = destino.get_Publica();
+ await this._servico.Salvar(destino);
+ if (this._servico.Sucesso)
+ {
+ if (publica)
+ {
+ long id = destino.get_Usuario().get_Id();
+ List<Usuario> usuarios = Recursos.Usuarios;
+ List<Task> tasks = new List<Task>();
+ foreach (Usuario usuario in usuarios)
+ {
+ if (id == usuario.get_Id())
+ {
+ continue;
+ }
+ Gestor.Model.Domain.Ferramentas.Tarefa tarefa1 = (Gestor.Model.Domain.Ferramentas.Tarefa)destino.Clone();
+ tarefa1.set_Id((long)0);
+ tarefa1.set_Usuario(usuario);
+ tasks.Add(this._servico.Salvar(tarefa1));
+ }
+ await Task.WhenAll(tasks);
+ }
+ await this.CarregarNotas();
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ return keyValuePairs;
+ }
+
+ public async Task<Gestor.Model.Domain.Ferramentas.Tarefa> SalvarNota(Gestor.Model.Domain.Ferramentas.Tarefa nota)
+ {
+ return await this._servico.Salvar(nota);
+ }
+
+ public void ToggleNotasConcluidas()
+ {
+ this.OcultarNotasConcluidas = !this.OcultarNotasConcluidas;
+ }
+ }
+}
\ No newline at end of file |