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/BI/NotasViewModel.cs | 311 +++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs (limited to 'Codemerx/Gestor.Application/ViewModels/BI/NotasViewModel.cs') 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 _usuarios; + + private Usuario _selectedUsuario; + + private Gestor.Model.Domain.Ferramentas.Tarefa _tarefa; + + private ObservableCollection _notas; + + private ObservableCollection _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 Notas + { + get + { + return this._notas; + } + set + { + this._notas = value; + base.OnPropertyChanged("Notas"); + } + } + + public ObservableCollection 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 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(Recursos.Usuarios.Where((Usuario x) => { + if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa()) + { + return false; + } + return !x.get_Excluido(); + }).OrderBy((Usuario x) => x.get_Nome()).ToList()); + this.SelectedUsuario = this.Usuarios.FirstOrDefault((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 notas = this.Notas; + if (notas.Any((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 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 tarefas = await this._servico.BuscarNotas(this.SelectedUsuario.get_Id()); + List 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(tarefas); + this.NotasConcluidas = new ObservableCollection(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>> Salvar(Gestor.Model.Domain.Ferramentas.Tarefa destino) + { + List> keyValuePairs; + Gestor.Model.Domain.Ferramentas.Tarefa tarefa = destino; + List configuracoes = Recursos.Configuracoes; + tarefa.set_AgendamentoRetroativo(configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 45)); + List> 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 usuarios = Recursos.Usuarios; + List tasks = new List(); + 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 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 -- cgit v1.2.3