summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs')
-rw-r--r--Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs514
1 files changed, 514 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs b/Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs
new file mode 100644
index 0000000..6adad6a
--- /dev/null
+++ b/Gestor.Application/ViewModels/Drawer/Ajuda/AtendimentosViewModel.cs
@@ -0,0 +1,514 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Model.Ajuda;
+using Gestor.Application.Servicos.Ajuda;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.API;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using Gestor.Model.Helper;
+using Gestor.Model.Resources;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Gestor.Application.ViewModels.Drawer.Ajuda
+{
+ public class AtendimentosViewModel : BaseViewModel
+ {
+ private readonly AjudaServico _ajudaServico;
+
+ private List<string> _status;
+
+ private string _webbody;
+
+ private Visibility _envioEmailVisibility = Visibility.Collapsed;
+
+ private Visibility _atendimentoVisibility;
+
+ private ObservableCollection<Atendimento> _atendimentos;
+
+ private Atendimento _selectedAtendimento;
+
+ private string _nome;
+
+ private string _ddd;
+
+ private string _telefone;
+
+ private string _email;
+
+ private string _assunto;
+
+ private string _idacesso;
+
+ private string _corpo;
+
+ private string _senhaacesso;
+
+ private ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> _arquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>();
+
+ private Gestor.Model.Domain.Common.ArquivoDigital _selectedAnexado = new Gestor.Model.Domain.Common.ArquivoDigital();
+
+ private string _head;
+
+ public ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> ArquivosAnexados
+ {
+ get
+ {
+ return this._arquivosAnexados;
+ }
+ set
+ {
+ this._arquivosAnexados = value;
+ base.OnPropertyChanged("ArquivosAnexados");
+ }
+ }
+
+ public string Assunto
+ {
+ get
+ {
+ return this._assunto;
+ }
+ set
+ {
+ this._assunto = value;
+ base.OnPropertyChanged("Assunto");
+ }
+ }
+
+ public ObservableCollection<Atendimento> Atendimentos
+ {
+ get
+ {
+ return this._atendimentos;
+ }
+ set
+ {
+ this._atendimentos = value;
+ base.OnPropertyChanged("Atendimentos");
+ }
+ }
+
+ public Visibility AtendimentoVisibility
+ {
+ get
+ {
+ return this._atendimentoVisibility;
+ }
+ set
+ {
+ this._atendimentoVisibility = value;
+ base.OnPropertyChanged("AtendimentoVisibility");
+ }
+ }
+
+ public string Corpo
+ {
+ get
+ {
+ return this._corpo;
+ }
+ set
+ {
+ this._corpo = value;
+ base.OnPropertyChanged("Corpo");
+ }
+ }
+
+ public string Ddd
+ {
+ get
+ {
+ return this._ddd;
+ }
+ set
+ {
+ this._ddd = value;
+ base.OnPropertyChanged("Ddd");
+ }
+ }
+
+ public string Email
+ {
+ get
+ {
+ return this._email;
+ }
+ set
+ {
+ this._email = value;
+ base.OnPropertyChanged("Email");
+ }
+ }
+
+ public Visibility EnvioEmailVisibility
+ {
+ get
+ {
+ return this._envioEmailVisibility;
+ }
+ set
+ {
+ this._envioEmailVisibility = value;
+ base.OnPropertyChanged("EnvioEmailVisibility");
+ }
+ }
+
+ public string Head
+ {
+ get
+ {
+ return this._head;
+ }
+ set
+ {
+ this._head = value;
+ base.OnPropertyChanged("Head");
+ }
+ }
+
+ public Gestor.Model.API.HorarioAtendimento HorarioAtendimento
+ {
+ get;
+ set;
+ }
+
+ public string IdAcesso
+ {
+ get
+ {
+ return this._idacesso;
+ }
+ set
+ {
+ this._idacesso = value;
+ base.OnPropertyChanged("IdAcesso");
+ }
+ }
+
+ public string Nome
+ {
+ get
+ {
+ return this._nome;
+ }
+ set
+ {
+ this._nome = value;
+ base.OnPropertyChanged("Nome");
+ }
+ }
+
+ public Gestor.Model.Domain.Common.ArquivoDigital SelectedAnexado
+ {
+ get
+ {
+ return this._selectedAnexado;
+ }
+ set
+ {
+ this._selectedAnexado = value;
+ base.OnPropertyChanged("SelectedAnexado");
+ }
+ }
+
+ public Atendimento SelectedAtendimento
+ {
+ get
+ {
+ return this._selectedAtendimento;
+ }
+ set
+ {
+ this._selectedAtendimento = value;
+ this.WorkOnSelectedAtendimento(value);
+ base.OnPropertyChanged("SelectedAtendimento");
+ }
+ }
+
+ public string SenhaAcesso
+ {
+ get
+ {
+ return this._senhaacesso;
+ }
+ set
+ {
+ this._senhaacesso = value;
+ base.OnPropertyChanged("SenhaAcesso");
+ }
+ }
+
+ public List<string> Status
+ {
+ get
+ {
+ return this._status;
+ }
+ set
+ {
+ this._status = value;
+ base.OnPropertyChanged("Status");
+ }
+ }
+
+ public string Telefone
+ {
+ get
+ {
+ return this._telefone;
+ }
+ set
+ {
+ this._telefone = value;
+ base.OnPropertyChanged("Telefone");
+ }
+ }
+
+ public string WebBody
+ {
+ get
+ {
+ string str = this._webbody;
+ if (str == null)
+ {
+ return null;
+ }
+ return str.ToUpper().Trim();
+ }
+ set
+ {
+ this._webbody = value;
+ base.OnPropertyChanged("WebBody");
+ }
+ }
+
+ public AtendimentosViewModel()
+ {
+ base.EnableButtons = true;
+ this._ajudaServico = new AjudaServico();
+ this.LoadCombo();
+ this.InitialLoad();
+ }
+
+ public async void Anexar()
+ {
+ List<Gestor.Model.Domain.Common.ArquivoDigital> arquivoDigitals = await base.AddAttachments(new List<Gestor.Model.Domain.Common.ArquivoDigital>(), new List<Gestor.Model.Domain.Common.ArquivoDigital>());
+ if (arquivoDigitals != null)
+ {
+ arquivoDigitals.AddRange(this.ArquivosAnexados);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(arquivoDigitals);
+ }
+ }
+
+ public void Delete(Gestor.Model.Domain.Common.ArquivoDigital arquivo)
+ {
+ if (this.SelectedAnexado == null)
+ {
+ return;
+ }
+ Gestor.Model.Domain.Common.ArquivoDigital arquivoDigital = this.ArquivosAnexados.First<Gestor.Model.Domain.Common.ArquivoDigital>((Gestor.Model.Domain.Common.ArquivoDigital x) => x.get_Descricao() == arquivo.get_Descricao());
+ this.ArquivosAnexados.Remove(arquivoDigital);
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>(this.ArquivosAnexados);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Enviar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ object obj;
+ try
+ {
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.Validate();
+ if (keyValuePairs1.Count <= 0)
+ {
+ CustomerData customerDatum = new CustomerData();
+ customerDatum.set_Corretora(Recursos.Empresa.get_Nome());
+ customerDatum.set_Name(this.Nome);
+ customerDatum.set_AreaCode(this.Ddd);
+ customerDatum.set_Number(this.Telefone);
+ customerDatum.set_Email(this.Email);
+ CustomerData customerDatum1 = customerDatum;
+ object[] corpo = new object[] { this.Corpo, this.IdAcesso, this.SenhaAcesso, ApplicationHelper.Versao, Recursos.Usuario.get_Id(), Recursos.Usuario.get_Login(), JsonConvert.SerializeObject(customerDatum1) };
+ string str = string.Format("{0}<hr><p><b>ID Acesso:</b> {1}<br><b>Senha Acesso:</b> {2}</p><p>VERSÃO DO SISTEMA: {3}<br />USUÁRIO SISTEMA:{4} {5}</p><p>{6}</p>", corpo);
+ CustomerAttendance customerAttendance = new CustomerAttendance();
+ customerAttendance.set_CustomerData(customerDatum1);
+ customerAttendance.set_Subject(this.Assunto);
+ customerAttendance.set_Body(str);
+ ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital> arquivosAnexados = this.ArquivosAnexados;
+ customerAttendance.set_Attachments(arquivosAnexados.Select<Gestor.Model.Domain.Common.ArquivoDigital, Attachment>((Gestor.Model.Domain.Common.ArquivoDigital x) => {
+ Attachment attachment = new Attachment();
+ attachment.set_Description(x.get_Descricao());
+ attachment.set_Extension(x.get_Extensao());
+ attachment.set_File(x.get_Arquivo());
+ return attachment;
+ }).ToList<Attachment>());
+ this.LimparComponentes();
+ this.SelecionaAtendimento();
+ if (await Connection.Post<CustomerAttendance>("Attendance/Send", customerAttendance) == null)
+ {
+ obj = null;
+ }
+ else
+ {
+ obj = new List<KeyValuePair<string, string>>();
+ ((List<KeyValuePair<string, string>>)obj).Add(new KeyValuePair<string, string>("fail", ""));
+ }
+ keyValuePairs = (List<KeyValuePair<string, string>>)obj;
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ }
+ catch (Exception exception)
+ {
+ keyValuePairs = new List<KeyValuePair<string, string>>()
+ {
+ new KeyValuePair<string, string>("fail", "")
+ };
+ }
+ return keyValuePairs;
+ }
+
+ private async void HabilitarAtendimento(Gestor.Model.API.HorarioAtendimento horario)
+ {
+ bool id;
+ string str;
+ if (horario == null || horario.get_Autorizado())
+ {
+ AtendimentosViewModel atendimentosViewModel = this;
+ Usuario usuario = Recursos.Usuario;
+ if (usuario != null)
+ {
+ id = usuario.get_Id() > (long)0;
+ }
+ else
+ {
+ id = false;
+ }
+ atendimentosViewModel.EnableButtons = id;
+ }
+ else
+ {
+ base.EnableButtons = false;
+ if (horario.get_InicioDia().HasValue)
+ {
+ string[] strArrays = new string[] { " de ", horario.get_InicioDia().DiaDaSemana(), " à ", horario.get_FimDia().DiaDaSemana(), ", das ", horario.get_InicioHora(), "hs às ", horario.get_FimHora(), "hs" };
+ str = string.Concat(strArrays);
+ }
+ else
+ {
+ string[] inicioHora = new string[] { " das ", horario.get_InicioHora(), "hs às ", horario.get_FimHora(), "hs" };
+ str = string.Concat(inicioHora);
+ }
+ string str1 = str;
+ string[] newLine = new string[] { "Prezado Cliente,", Environment.NewLine, Environment.NewLine, "Informamos Nosso horário de atendimento e recepção dos mesmos é ", str1, ".", Environment.NewLine, "Infelizmente não realizamos agendamento de data/hora de atendimento, por gentileza realize a solicitação dentro do horário comercial que retornaremos a você." };
+ await base.ShowMessage(string.Concat(newLine), "OK", "", false);
+ }
+ }
+
+ private async void InitialLoad()
+ {
+ base.IsEnabled = false;
+ this.HorarioAtendimento = await Connection.Get<Gestor.Model.API.HorarioAtendimento>("Attendance", true, false);
+ this.HabilitarAtendimento(this.HorarioAtendimento);
+ base.IsEnabled = true;
+ }
+
+ public void LimparComponentes()
+ {
+ this.Nome = Recursos.Usuario.get_Nome();
+ this.Ddd = Recursos.Usuario.get_Prefixo();
+ this.Telefone = Recursos.Usuario.get_Telefone();
+ this.Email = Recursos.Usuario.get_Email();
+ this.Assunto = null;
+ this.IdAcesso = null;
+ this.SenhaAcesso = null;
+ this.Corpo = string.Empty;
+ this.ArquivosAnexados = new ObservableCollection<Gestor.Model.Domain.Common.ArquivoDigital>();
+ }
+
+ private void LoadCombo()
+ {
+ this.Status = new List<string>()
+ {
+ "PENDENTES",
+ "FINALIZADOS"
+ };
+ }
+
+ public void SelecionaAtendimento()
+ {
+ if (this.Atendimentos != null && this.Atendimentos.Count > 0)
+ {
+ this.SelectedAtendimento = this.Atendimentos[0];
+ }
+ this.AtendimentoVisibility = Visibility.Visible;
+ this.EnvioEmailVisibility = Visibility.Collapsed;
+ }
+
+ public List<KeyValuePair<string, string>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = ValidationHelper.AddValue();
+ if (string.IsNullOrWhiteSpace(this.Nome))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Nome", Messages.get_Obrigatorio(), true);
+ }
+ if (string.IsNullOrWhiteSpace(this.Ddd))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Ddd", Messages.get_Obrigatorio(), true);
+ }
+ else if (!ValidationHelper.ValidacaoPrefixo(this.Ddd))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Ddd", Messages.get_Invalido(), true);
+ }
+ if (string.IsNullOrWhiteSpace(this.Telefone))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Telefone", Messages.get_Obrigatorio(), true);
+ }
+ else if (!ValidationHelper.ValidacaoTelefone(this.Telefone))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Telefone", Messages.get_Invalido(), true);
+ }
+ if (string.IsNullOrWhiteSpace(this.Email))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Email", Messages.get_Obrigatorio(), true);
+ }
+ else if (!ValidationHelper.ValidacaoEmail(this.Email))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Email", Messages.get_Invalido(), true);
+ }
+ if (string.IsNullOrWhiteSpace(this.Corpo))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Corpo", Messages.get_Obrigatorio(), true);
+ }
+ if (string.IsNullOrWhiteSpace(this.Assunto))
+ {
+ ValidationHelper.AddValue<string, string>(keyValuePairs, "Assunto", Messages.get_Obrigatorio(), true);
+ }
+ return keyValuePairs;
+ }
+
+ private async void WorkOnSelectedAtendimento(Atendimento value)
+ {
+ if (value != null)
+ {
+ this.WebBody = await this._ajudaServico.BuscarCorpoAtendimentos(value.IdAtendimento);
+ }
+ }
+
+ public async void WorkOnSelectedStatus(string value)
+ {
+ this.Atendimentos = await this._ajudaServico.BuscarAtendimentos(value);
+ this.SelecionaAtendimento();
+ }
+ }
+} \ No newline at end of file