summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs292
1 files changed, 292 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs
new file mode 100644
index 0000000..abd3dde
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Generic/DialogAdvertisingViewModel.cs
@@ -0,0 +1,292 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Model;
+using Gestor.Common.Validation;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Gestor.Application.ViewModels.Generic
+{
+ public class DialogAdvertisingViewModel : BaseViewModel
+ {
+ private readonly bool _isPromo;
+
+ private string _urlPesquisa;
+
+ private Visibility _visualizarNaoExibirNovamente = Visibility.Hidden;
+
+ private string _titulo = "";
+
+ private string _imagem = "";
+
+ public string Url = "";
+
+ private bool _naoQuero;
+
+ public string Imagem
+ {
+ get
+ {
+ return this._imagem;
+ }
+ set
+ {
+ this._imagem = value;
+ base.OnPropertyChanged("Imagem");
+ }
+ }
+
+ public bool NaoVer
+ {
+ get
+ {
+ return this._naoQuero;
+ }
+ set
+ {
+ this._naoQuero = value;
+ base.OnPropertyChanged("NaoVer");
+ }
+ }
+
+ public string Titulo
+ {
+ get
+ {
+ return this._titulo;
+ }
+ set
+ {
+ this._titulo = value;
+ base.OnPropertyChanged("Titulo");
+ }
+ }
+
+ public Visibility VisualizarNaoExibirNovamente
+ {
+ get
+ {
+ return this._visualizarNaoExibirNovamente;
+ }
+ set
+ {
+ this._visualizarNaoExibirNovamente = value;
+ base.OnPropertyChanged("VisualizarNaoExibirNovamente");
+ }
+ }
+
+ public DialogAdvertisingViewModel(JObject jsonAd, bool isPromo)
+ {
+ bool flag;
+ bool flag1 = false;
+ this._isPromo = isPromo;
+ if (this._isPromo)
+ {
+ this.CarregaImagem(jsonAd);
+ JToken item = jsonAd.get_Item("NaoExibirNovamente");
+ if (item != null)
+ {
+ flag = Extensions.Value<bool>(item);
+ }
+ else
+ {
+ flag = true;
+ }
+ flag1 = flag;
+ }
+ else
+ {
+ this.CarregaPesquisa(jsonAd);
+ }
+ this.VisualizarNaoExibirNovamente = (flag1 ? Visibility.Visible : Visibility.Hidden);
+ }
+
+ private void CarregaImagem(JObject json)
+ {
+ string str;
+ string str1;
+ string str2;
+ if (json == null)
+ {
+ return;
+ }
+ JToken item = json.get_Item("Titulo");
+ if (item != null)
+ {
+ str = Extensions.Value<string>(item);
+ }
+ else
+ {
+ str = null;
+ }
+ this.Titulo = str;
+ JToken jToken = json.get_Item("Url");
+ if (jToken != null)
+ {
+ str1 = Extensions.Value<string>(jToken);
+ }
+ else
+ {
+ str1 = null;
+ }
+ this.Url = str1;
+ JToken item1 = json.get_Item("Imagem");
+ if (item1 != null)
+ {
+ str2 = Extensions.Value<string>(item1);
+ }
+ else
+ {
+ str2 = null;
+ }
+ this.Imagem = str2;
+ }
+
+ private void CarregaPesquisa(JObject json)
+ {
+ string str;
+ string str1;
+ string str2;
+ string str3;
+ if (json == null)
+ {
+ return;
+ }
+ JToken item = json.get_Item("Titulo");
+ if (item != null)
+ {
+ str = Extensions.Value<string>(item);
+ }
+ else
+ {
+ str = null;
+ }
+ this.Titulo = str;
+ JToken jToken = json.get_Item("Imagem");
+ if (jToken != null)
+ {
+ str1 = Extensions.Value<string>(jToken);
+ }
+ else
+ {
+ str1 = null;
+ }
+ this.Imagem = str1;
+ JToken item1 = json.get_Item("UrlPost");
+ if (item1 != null)
+ {
+ str2 = Extensions.Value<string>(item1);
+ }
+ else
+ {
+ str2 = null;
+ }
+ this._urlPesquisa = str2;
+ if (Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(this._urlPesquisa))
+ {
+ return;
+ }
+ JToken jToken1 = json.get_Item("UrlFixa");
+ if (jToken1 != null)
+ {
+ str3 = Extensions.Value<string>(jToken1);
+ }
+ else
+ {
+ str3 = null;
+ }
+ this._urlPesquisa = str3;
+ this.Url = this._urlPesquisa;
+ }
+
+ public void CriarConfiguracaoPadrao(string configFile)
+ {
+ File.WriteAllText(configFile, JsonConvert.SerializeObject(new Gestor.Application.Model.Configuracoes()
+ {
+ LinkPromo = "",
+ NaoverPromo = this.NaoVer
+ }, 1));
+ }
+
+ public void EnviarPesquisa()
+ {
+ string str;
+ try
+ {
+ using (HttpClient httpClient = new HttpClient())
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ httpClient.set_Timeout(TimeSpan.FromSeconds(15));
+ httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("company-key", "$2b$10$arV/viDP6N.5KX9sRt/.MOo8Gv5FFvHIx0P6HZyuky51P3ItWBV0u");
+ var variable = new { customers = new u003cu003ef__AnonymousType49<string, string, string, string, long>[] { new { nome = Recursos.Usuario.get_Nome(), email = (Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(Recursos.Usuario.get_Email()) ? string.Format("{0}-{1}@sememail.com", Recursos.Usuario.get_Id(), ApplicationHelper.IdFornecedor) : Recursos.Usuario.get_Email()), corretora = Recursos.Empresa.get_NomeSocial(), produto = "Gestor", idfornecedor = ApplicationHelper.IdFornecedor } } };
+ HttpResponseMessage result = httpClient.PostAsync(this._urlPesquisa, variable.ToHttpContent(null, "application/json")).Result;
+ if (result.get_IsSuccessStatusCode())
+ {
+ JToken item = JObject.Parse(result.get_Content().ReadAsStringAsync().Result).get_Item("customers");
+ if (item != null)
+ {
+ JToken jToken = item.get_Item(0);
+ if (jToken != null)
+ {
+ JToken item1 = jToken.get_Item("shortUrl");
+ if (item1 != null)
+ {
+ str = Extensions.Value<string>(item1);
+ }
+ else
+ {
+ str = null;
+ }
+ }
+ else
+ {
+ str = null;
+ }
+ }
+ else
+ {
+ str = null;
+ }
+ string str1 = str;
+ if (!Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(str1))
+ {
+ this.Url = str1;
+ }
+ else
+ {
+ return;
+ }
+ }
+ else
+ {
+ return;
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ }
+ }
+
+ public void SalvaEditarArquivoConfig(bool visto = false)
+ {
+ if (!File.Exists("config.json"))
+ {
+ this.CriarConfiguracaoPadrao("config.json");
+ }
+ Gestor.Application.Model.Configuracoes naoVer = JsonConvert.DeserializeObject<Gestor.Application.Model.Configuracoes>(File.ReadAllText("config.json"));
+ naoVer.LinkPromo = (this._isPromo ? this.Imagem : this._urlPesquisa);
+ naoVer.NaoverPromo = this.NaoVer;
+ File.WriteAllText("config.json", JsonConvert.SerializeObject(naoVer, 1));
+ }
+ }
+} \ No newline at end of file