From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../ViewModels/Generic/DialogTarefaViewModel.cs | 296 +++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 Gestor.Application/ViewModels/Generic/DialogTarefaViewModel.cs (limited to 'Gestor.Application/ViewModels/Generic/DialogTarefaViewModel.cs') diff --git a/Gestor.Application/ViewModels/Generic/DialogTarefaViewModel.cs b/Gestor.Application/ViewModels/Generic/DialogTarefaViewModel.cs new file mode 100644 index 0000000..9041cd3 --- /dev/null +++ b/Gestor.Application/ViewModels/Generic/DialogTarefaViewModel.cs @@ -0,0 +1,296 @@ +using CsQuery.ExtensionMethods.Internal; +using Gestor.Application.Helpers; +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.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Windows; + +namespace Gestor.Application.ViewModels.Generic +{ + public class DialogTarefaViewModel : BaseSegurosViewModel + { + private bool _showPublica; + + private bool _nota; + + private Visibility _cabecalho; + + private Visibility _agendamento; + + private Visibility _status; + + private List _telefones; + + private ObservableCollection _usuarios; + + private Gestor.Model.Domain.Ferramentas.Tarefa _tarefa; + + private DateTime _dataAgendamento = Funcoes.GetNetworkTime(); + + private DateTime _horaAgendamento = Funcoes.GetNetworkTime(); + + private ObservableCollection _responsaveis = new ObservableCollection(); + + private Usuario _selectedUsuario; + + private bool _isAnotacoes = true; + + public Visibility Agendamento + { + get + { + return this._agendamento; + } + set + { + this._agendamento = value; + this.MutateVerbose(ref this._agendamento, value, this.OnRaisePropertyChanged(), "Agendamento"); + } + } + + public Visibility Cabecalho + { + get + { + return this._cabecalho; + } + set + { + this._cabecalho = value; + this.MutateVerbose(ref this._cabecalho, value, this.OnRaisePropertyChanged(), "Cabecalho"); + } + } + + public DateTime DataAgendamento + { + get + { + return this._dataAgendamento; + } + set + { + this._dataAgendamento = value; + if (this.Tarefa != null) + { + this.Tarefa.set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", value, this.Tarefa.get_Agendamento()))); + } + this.MutateVerbose(ref this._dataAgendamento, value, this.OnRaisePropertyChanged(), "DataAgendamento"); + } + } + + public DateTime HoraAgendamento + { + get + { + return this._horaAgendamento; + } + set + { + this._horaAgendamento = value; + if (this.Tarefa != null) + { + this.Tarefa.set_Agendamento(DateTime.Parse(string.Format("{0:d} {1:T}", this.Tarefa.get_Agendamento(), value))); + } + this.MutateVerbose(ref this._horaAgendamento, value, this.OnRaisePropertyChanged(), "HoraAgendamento"); + } + } + + public bool IsAnotacoes + { + get + { + return this._isAnotacoes; + } + set + { + this._isAnotacoes = value; + base.OnPropertyChanged("IsAnotacoes"); + } + } + + public bool Nota + { + get + { + return this._nota; + } + set + { + this._nota = value; + if (!value) + { + return; + } + this.Cabecalho = Visibility.Collapsed; + this.Status = Visibility.Collapsed; + } + } + + public ObservableCollection Responsaveis + { + get + { + return this._responsaveis; + } + set + { + this._responsaveis = value; + base.OnPropertyChanged("Responsaveis"); + } + } + + public Usuario SelectedUsuario + { + get + { + return this._selectedUsuario; + } + set + { + this._selectedUsuario = value; + base.OnPropertyChanged("SelectedUsuario"); + } + } + + public bool ShowPublica + { + get + { + return this._showPublica; + } + set + { + this._showPublica = value; + base.OnPropertyChanged("ShowPublica"); + } + } + + public Visibility Status + { + get + { + return this._status; + } + set + { + this._status = value; + this.MutateVerbose(ref this._status, value, this.OnRaisePropertyChanged(), "Status"); + } + } + + public Gestor.Model.Domain.Ferramentas.Tarefa Tarefa + { + get + { + return this._tarefa; + } + set + { + DateTime networkTime = Funcoes.GetNetworkTime(); + this.DataAgendamento = (value != null ? value.get_Agendamento() : networkTime); + this.HoraAgendamento = (value != null ? value.get_Agendamento() : networkTime); + this.MutateVerbose(ref this._tarefa, value, this.OnRaisePropertyChanged(), "Tarefa"); + } + } + + public List Telefones + { + get + { + return this._telefones; + } + set + { + this._telefones = value; + this.MutateVerbose>(ref this._telefones, value, this.OnRaisePropertyChanged(), "Telefones"); + } + } + + public ObservableCollection Usuarios + { + get + { + return this._usuarios; + } + set + { + this._usuarios = value; + this.MutateVerbose>(ref this._usuarios, value, this.OnRaisePropertyChanged(), "Usuarios"); + } + } + + public DialogTarefaViewModel(Gestor.Model.Domain.Ferramentas.Tarefa tarefa, List telefones, bool nota = false, bool agendamento = false) + { + this.ShowPublica = (!nota ? false : tarefa.get_HabilitarPublica()); + this.Telefones = telefones; + 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.Nota = nota; + if (tarefa.get_Entidade() == 1) + { + tarefa.set_Anotacoes(tarefa.get_Descricao()); + tarefa.set_Descricao(string.Empty); + } + if (agendamento) + { + this.Agendamento = Visibility.Collapsed; + } + if (tarefa.get_UsuariosVinculados() != null) + { + ExtensionMethods.AddRange(this.Responsaveis, tarefa.get_UsuariosVinculados()); + } + this.Responsaveis.ToList().ForEach((Usuario x) => this.Usuarios.Remove(this.Usuarios.FirstOrDefault((Usuario u) => u.get_Id() == x.get_Id()))); + this.Tarefa = tarefa; + } + + public void AdcionarResponsavel() + { + if (this.SelectedUsuario == null || this.Responsaveis.Any((Usuario x) => (object)x == (object)this.SelectedUsuario)) + { + return; + } + this.Responsaveis.Add(this.SelectedUsuario); + this.Tarefa.set_UsuariosVinculados(this.Responsaveis.ToList()); + this.Usuarios.Remove(this.SelectedUsuario); + this.SelectedUsuario = null; + } + + private Action OnRaisePropertyChanged() + { + return (PropertyChangedEventArgs args) => { + PropertyChangedEventHandler propertyChangedEventHandler = this.RaisePropertyChanged; + if (propertyChangedEventHandler == null) + { + return; + } + propertyChangedEventHandler(this, args); + }; + } + + public void RemoverResponsavel(Usuario selectedUsuario) + { + if (selectedUsuario == null) + { + return; + } + this.Responsaveis.Remove(selectedUsuario); + this.Tarefa.set_UsuariosVinculados(this.Responsaveis.ToList()); + this.Usuarios.Add(selectedUsuario); + selectedUsuario = null; + } + + public event PropertyChangedEventHandler RaisePropertyChanged; + } +} \ No newline at end of file -- cgit v1.2.3