Esempio n. 1
0
        public ApplicantUpdateRequestValidator()
        {
            RuleFor(applicant => applicant.ID).NotEmpty().GreaterThan(0);
            RuleFor(applicant => applicant.Name).NotNull().MinimumLength(5);
            RuleFor(applicant => applicant.FamilyName).NotNull().MinimumLength(5);
            RuleFor(applicant => applicant.Address).NotNull().MinimumLength(10);
            RuleFor(applicant => applicant.Age).NotNull().ExclusiveBetween(20, 60);
            RuleFor(applicant => applicant.EmailAddress).NotEmpty().NotNull().WithMessage("Email address is required ")
            .EmailAddress().WithMessage("The email must be a valid email address");

            RuleFor(applicant => applicant.EmailAddress).Matches(@"^[^@\s]+@[^@\s]+\.[^@\s]+$").WithMessage(c =>
            {
                //this._logger.LogInformation("Email not valid");
                return("Email not valid");
            });
            // RuleFor(m => m.CountryOfOrigin).NotNull().SetValidator(new CountryValidator(restClient));
            RuleFor(applicant => applicant.CountryOfOrigin).NotNull().NotEmpty().MustAsync(async(country, cancellation) =>
            {
                string url            = InfrastructureDefaults.RestCountryUrl + country;
                string clientResponse = await HttpServiceHelper.GetHttpClient(url);
                // this._logger.LogInformation(clientResponse);
                if (!string.IsNullOrEmpty(clientResponse))
                {
                    return(true);
                }

                return(false);
            }).WithMessage("Country name is not valid.");
        }
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var hostingEnvironment = context.Services.GetHostingEnvironment();
            var configuration      = context.Services.GetConfiguration();

            Configure <AbpDbContextOptions>(options =>
            {
                options.UseSqlServer();
            });

            Configure <AbpMultiTenancyOptions>(options =>
            {
                options.IsEnabled = false;
            });

            context.Services.AddSwaggerGen(
                options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Repository API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);
                options.CustomSchemaIds(type => type.FullName);

                var xmlFile = "Questys.RestfullAPI.Repository.HttpApi.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                if (File.Exists(xmlPath))
                {
                    options.IncludeXmlComments(xmlPath);
                }
            });

            context.Services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicyName, builder =>
                {
                    builder
                    .WithOrigins(
                        configuration["App:CorsOrigins"]
                        .Split(",", StringSplitOptions.RemoveEmptyEntries)
                        .Select(o => o.RemovePostFix("/"))
                        .ToArray()
                        )
                    .WithAbpExposedHeaders()
                    .SetIsOriginAllowedToAllowWildcardSubdomains()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });

            //context.Services
            //    .AddHealthChecks()
            //    .AddSqlServer(configuration.GetConnectionString(RepositoryDbProperties.ConnectionStringName));

            HttpServiceHelper.SetHttpContextAccessorService(
                context.Services.BuildServiceProvider()?.GetService <IHttpContextAccessor>());
        }
        public IEnumerable <RelatorioProdutoAppModel> ObterRelatorioDeProdutos()
        {
            var httpResponse = HttpServices.HttpServiceEstoque.ObterRelatorioDeProdutos();

            if (!httpResponse.IsSuccessStatusCode)
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new System.Exception(erro);
            }

            var produtos = httpResponse.Content.ReadAsAsync <IEnumerable <RelatorioProdutoAppModel> >().Result;

            return(produtos);
        }
        public IEnumerable <FuncionarioAppModel> ObterTodosOsFuncionarios()
        {
            var httpResponse = HttpServiceGlobal.ObterTodosOsFuncionarios();

            if (!httpResponse.IsSuccessStatusCode)
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new System.Exception(erro);
            }

            var funcionarios = httpResponse.Content.ReadAsAsync <IEnumerable <FuncionarioAppModel> >().Result;

            return(funcionarios);
        }
        public IEnumerable <RelatorioClienteAppModel> GerarRelatorio()
        {
            var httpResponse = HttpServiceGlobal.ObterClientesParaRelatorio();

            if (!httpResponse.IsSuccessStatusCode)
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new System.Exception(erro);
            }

            var clientes = httpResponse.Content.ReadAsAsync <IEnumerable <RelatorioClienteAppModel> >().Result;

            return(clientes);
        }
Esempio n. 6
0
        public int CountObterFechamentosDoDia(string filtroDia)
        {
            int count = 0;

            var httpResponse = HttpServices.HttpServiceCaixa.ObterCountFechamentos(filtroDia);

            if (httpResponse.IsSuccessStatusCode)
            {
                count = httpResponse.Content.ReadAsAsync <int>().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(count);
        }
Esempio n. 7
0
        public IEnumerable <MovimentoCaixaAppModel> ObterRetiradasDoCaixa(string diaFechamento)
        {
            IEnumerable <MovimentoCaixaAppModel> entradas = new List <MovimentoCaixaAppModel>();

            var httpResponse = HttpServices.HttpServiceCaixa.ObterRetiradasDoDia(diaFechamento);

            if (httpResponse.IsSuccessStatusCode)
            {
                entradas = httpResponse.Content.ReadAsAsync <IEnumerable <MovimentoCaixaAppModel> >().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(entradas);
        }
Esempio n. 8
0
        public async Task <IEnumerable <FechamentoDiarioAppModel> > ObterFechamentosDoDiaAsync(string diaFechamento, int currentPage, int maxRows)
        {
            IEnumerable <FechamentoDiarioAppModel> entradas = new List <FechamentoDiarioAppModel>();

            var httpResponse = HttpServices.HttpServiceCaixa.ObterFechamentos(currentPage, maxRows, diaFechamento);

            if (httpResponse.IsSuccessStatusCode)
            {
                entradas = await httpResponse.Content.ReadAsAsync <IEnumerable <FechamentoDiarioAppModel> >();
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(entradas);
        }
        public ResumoPagamentosCaixaAppModel ObterResumoDosPagamentosEEntradasDoCaixa(string dataInicio, string dataFim)
        {
            ResumoPagamentosCaixaAppModel resumo = null;

            var httpResponse = HttpServices.HttpServiceVenda.ObterResumoDosPagamentosEEntradasDoCaixa(dataInicio, dataFim);

            if (httpResponse.IsSuccessStatusCode)
            {
                resumo = httpResponse.Content.ReadAsAsync <ResumoPagamentosCaixaAppModel>().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(resumo);
        }
        public IEnumerable <ResumoVendasPorFuncionarioAppModel> ObterResumoDeVendasPorFuncionario(string dataInicio, string dataFim, string idFuncionario)
        {
            IEnumerable <ResumoVendasPorFuncionarioAppModel> resumo = null;

            var httpResponse = HttpServices.HttpServiceVenda.ObterResumoDeVendasPorFuncionario(dataInicio, dataFim, idFuncionario);

            if (httpResponse.IsSuccessStatusCode)
            {
                resumo = httpResponse.Content.ReadAsAsync <IEnumerable <ResumoVendasPorFuncionarioAppModel> >().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(resumo);
        }
        public ResumoFinanceiroMensalAppModel ObterResumoFinanceiroMensal(string mesAno)
        {
            ResumoFinanceiroMensalAppModel resumo = null;

            var httpResponse = HttpServices.HttpServiceVenda.ObterResumoFinanceiroDoMes(mesAno);

            if (httpResponse.IsSuccessStatusCode)
            {
                resumo = httpResponse.Content.ReadAsAsync <ResumoFinanceiroMensalAppModel>().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(resumo);
        }
        public ResumoDebitosAReceberAppModel ObterResumoDebitosAReceber(string dataReferencia)
        {
            ResumoDebitosAReceberAppModel resumo = null;

            var httpResponse = HttpServices.HttpServiceVenda.ObterDebitosDosClientesAReceber(dataReferencia);

            if (httpResponse.IsSuccessStatusCode)
            {
                resumo = httpResponse.Content.ReadAsAsync <ResumoDebitosAReceberAppModel>().Result;
            }
            else
            {
                var erro = HttpServiceHelper.ObterMensagemHttpResponse(httpResponse);
                throw new BusinessException(erro);
            }

            return(resumo);
        }
Esempio n. 13
0
        private static void GetValidContactsFromXdb(XConnectClient client)
        {
            HttpServiceHelper obj = new HttpServiceHelper();
            var listOfEmails      = OutlookUtility.ReadEmailsFromInbox();
            var emailList         = JsonConvert.DeserializeObject <List <OutlookEmailModel> >(listOfEmails);

            if (emailList == null)
            {
                return;
            }

            bool isvalidUser = false;

            foreach (var outlookEmailModel in emailList)
            {
                isvalidUser = SearchContacts(client, outlookEmailModel.EmailFrom);
                if (isvalidUser)
                {
                    string LUISAppUrl = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatLUISAppUrl];
                    string oleAppId   = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatOleAppId];
                    string oleAppkey  = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatOleAppkey];

                    string apiToTrigger = ConfigurationManager.AppSettings[Constants.APIToTriggerGoals];

                    var query = String.Concat(LUISAppUrl, oleAppId, "", oleAppkey,
                                              "" + outlookEmailModel.EmailBody);
                    var data = obj.GetServiceResponse <LuisResult>(query, false);
                    if (data != null)
                    {
                        outlookEmailModel.Intent = data.TopScoringIntent.Intent.ToLower();
                        // Call  sitecore api controller to trigger call;
                        obj.HttpGet(apiToTrigger);
                    }
                }
            }
        }
Esempio n. 14
0
 public static void Init(TestContext context)
 {
     _httpServiceHelperController = new HttpServiceHelper();
 }
Esempio n. 15
0
        private void HandleBrokerHook(BrokerData brokerData, WebHookData hookData)
        {
            var step = 0;

            try
            {
                step = 1;

                var httpService = new HttpServiceHelper();
                var config      = new DataUpdatesConfig {
                    FromTime = hookData.LastExecutionTime
                };

                var serviceData = this.BLL.GetServiceData(hookData.ServiceName, brokerData);
                if (serviceData == null)
                {
                    throw new Exception($"No Service Data: {hookData.ServiceName}");
                }

                step = 2;

                var proxyURL  = this.Config.ProxyServerURI; // "http://proxy.crtv.co.il";
                var proxyPort = serviceData.Port;

                var generator = new JWTGenerator(this.Config.JWTSecretKey);
                var token     = generator.GenerateToken(new {
                    brokerName = brokerData.Name,
                    role       = "Broker"
                });

                step = 3;

                var updatesURI    = $"{proxyURL}:{proxyPort}/{hookData.ServiceName}/updates";
                var serviceResult = httpService.POST(updatesURI, config, headers: new Dictionary <string, string>
                {
                    ["Content-Type"]  = "application/json",
                    ["Authorization"] = $"Bearer {token}"
                });

                step = 4;

                // TODO ->> StatusCode
                if (!serviceResult.Success)
                {
                    // remove html content
                    if (serviceResult.Content.Contains("<!DOCTYPE"))
                    {
                        serviceResult.Content = serviceResult.Content.Split('<').FirstOrDefault();
                    }

                    throw new Exception($"Get Updates from {updatesURI} -> {serviceResult.Content}");
                }

                var updates    = serviceResult.Content;
                var hasUpdates = !string.IsNullOrEmpty(updates) && updates != "[]";

                step = 5;

                // push updates
                if (hasUpdates)
                {
                    this.Logger.Info("WebHooksProcess", $"#{hookData.Id}, POST {hookData.ServiceName} Updates to {hookData.HookURL}");

                    var pushResult = httpService.POST($"{hookData.HookURL}", updates, headers: new Dictionary <string, string>
                    {
                        ["Content-Type"] = "application/json"
                    });

                    step = 6;

                    if (!pushResult.Success)
                    {
                        throw new Exception($"Push Updates to {hookData.HookURL} -> {serviceResult.Content}");
                    }
                }

                step = 7;

                hookData.LastExecutionTime = DateTime.Now; // update the last execution time
                this.BLL.UpdateWebHookLastExecutionTime(hookData);
            }
            catch (Exception ex)
            {
                ex.Data.Add("Method", "WebHooksProcess.HandleBrokerHook");
                ex.Data.Add("HookId", hookData.Id);
                ex.Data.Add("BrokerName", hookData.BrokerName);
                ex.Data.Add("ServiceName", hookData.ServiceName);
                ex.Data.Add("Step", step);
                this.Logger.Error("WebHooksProcess", ex);
            }
        }
 public IntuitAPIManagerSyncHttp(IntuitAPIConfig Config)
 {
     this.Config      = Config;
     this.HttpService = new HttpServiceHelper();
 }