public async Task <decimal?> AllianzQuoteHandler(BaseQuote bq)
        {
            Console.WriteLine("Allianz Start");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var startDate = DateTime.Now.ToString("yyyy-MM-dd");
            var endDate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("yyyy-MM-dd");
            var request   = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://ihealthapi.agaassistance.com.au/v1/quote?Adults={bq.Allianzadult}&Dependants={bq.Allianzchild}&StartDate={startDate}&EndDate={endDate}"),
                Headers =
                {
                    {
                        HttpRequestHeader.Referer.ToString(),
                        "https://allianzassistancehealth.com.au/oneweb/angular/iHealth/index.html?appKey=troy-1176533814&&"
                    },
                    { "Origin",                                    "https://allianzassistancehealth.com.au" },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                      },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                         },
                    { "timestamp",                                 DateTime.Now.Ticks.ToString()            },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json"                       },
                    { "X-Requested-With",                          "XMLHttpRequest"                         },
                    { "DNT",                                       "1"                                      },
                    { "Accept",                                    "application/json, text/plain, */*"      },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0"
                    }
                }
            };

            // var client = _clientFactory.CreateClient();
            var response = await client.SendAsync(request);

            var result = await response.Content.ReadAsStringAsync();

            JObject jObject = JObject.Parse(result);
            var     tt      = jObject["premium"]["amount"].ToString();

            //var tt =  jObject.Parse(response)["premium"]["amount"].ToString();
            Console.WriteLine($"Allianz: {stopwatch.Elapsed.ToString()} has elapsed");
            stopwatch.Stop();
            return(Decimal.Parse(tt));
        }
        /// <summary>
        ///     FundID =17
        ///     single = S; Single Parent =P
        ///     Family = F; Couple=D
        /// </summary>
        /// <returns></returns>
        public async Task <decimal?> MedibankQuoteHandler(BaseQuote bq)
        {
            Console.WriteLine("Medibank Start");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var startdate = DateTime.Now.ToString("d", new CultureInfo("en-AU"));
            var enddate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("d", new CultureInfo("en-AU"));
            var request   = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://www.members.medibankoshc.com.au/api/quotes/new?startDate={startdate}&visaEndDate={enddate}&fundId=17&scope={bq.medibankCoverType}&courseCompletionDate={enddate}"),
                Headers =
                {
                    { HttpRequestHeader.Referer.ToString(),        "https://www.medibankoshc.com.au/get-a-quote/" },
                    { "Origin",                                    "https://www.medibankoshc.com.au"              },
                    {
                        HttpRequestHeader.CacheControl.ToString(),
                        "no-store, no-cache, must-revalidate, proxy-revalidate"
                    },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                            },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                               },
                    { "pragma",                                    "no-cache"                                     },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json"                             },
                    { "x-api-key",                                 "WeDmY4YdhyhLxvVrKEiO6OvLod7kiin5HaOBTjxe"     },
                    { "DNT",                                       "1"                                            },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
                    }
                }
            };
            //  var client = _clientFactory.CreateClient();
            var response = await client.SendAsync(request).Result.Content.ReadAsStringAsync();

            var t = JObject.Parse(response)["amount"].ToString();

            Console.WriteLine($"Medibank: {stopwatch.Elapsed.ToString()} has elapsed");
            stopwatch.Stop();
            return(Decimal.Parse(t));
        }
        //private readonly IHttpClientFactory _clientFactory;
        //private readonly ServiceProvider services = new ServiceCollection().AddHttpClient().BuildServiceProvider();

        //public OshcApiHandler()
        //{
        //    _clientFactory = services.GetRequiredService<IHttpClientFactory>();
        //}

        public async Task <decimal?> NibApiHandler(BaseQuote bq)
        {
            var stopwatch = new Stopwatch();

            Console.WriteLine("NIB Start");
            stopwatch.Start();
            var startDate = DateTime.Now.ToString("dd-MMM-yyyy");
            var endDate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("dd-MMM-yyyy");

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://www.nib.com.au/overseas-students/join/api/price?startDate={startDate}&endDate={endDate}&scale={bq.NibCoverType}"),
                Headers =
                {
                    { HttpRequestHeader.Referer.ToString(),        "https://www.nib.com.au/overseas-students" },
                    { "Origin",                                    "https://allianzassistancehealth.com.au"   },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                        },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                           },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json, text/plain, */*"        },
                    { "DNT",                                       "1"                                        },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0"
                    }
                }
            };
            //  var client = _clientFactory.CreateClient();
            var t = await client.SendAsync(request).Result.Content.ReadAsStringAsync();

            Console.WriteLine($"NIB: {stopwatch.Elapsed.ToString()} has elapsed");
            stopwatch.Stop();
            return(Decimal.Parse(t));
        }
Example #4
0
        public int OshcGetQuote(string Covertype, int duration)
        {
            var bq = new BaseQuote
            {
                duration = duration
            };

            var op = new OshcQuote
            {
                Date     = DateTime.UtcNow.AddHours(10),
                Duration = duration
            };

            // Generating ID using covertype, duration and datetime
            op.Id = Covertype + "-" + duration + "-" + op.Date.ToString("ddMMyyHH");
            if (Covertype == "Single")
            {
                bq.Allianzadult      = "1";
                bq.Allianzchild      = "0";
                bq.NibCoverType      = "Single";
                bq.medibankCoverType = "S";
                op.Covertype         = "Single";
            }
            else if (Covertype == "Couple")
            {
                bq.Allianzadult      = "2";
                bq.Allianzchild      = "0";
                bq.NibCoverType      = "Couple";
                bq.medibankCoverType = "D";
                op.Covertype         = "Couple";
            }
            else if (Covertype == "Family")
            {
                bq.Allianzadult      = "2";
                bq.Allianzchild      = "1";
                bq.NibCoverType      = "Family";
                bq.medibankCoverType = "F";
                op.Covertype         = "Family";
            }
            else if (Covertype == "Parent")
            {
                bq.Allianzadult      = "1";
                bq.Allianzchild      = "1";
                bq.NibCoverType      = "Family";
                bq.medibankCoverType = "P";
                op.Covertype         = "Single Parent";
            }

            //  Console.WriteLine($"Sending to Handler: {stopwatch.Elapsed.ToString()} has elapsed");

            var oshcApiHandler = new OshcApiHandler();

            //Parallel request to reduce processing time
            //Might not work in linux based installations. Check before deploying
            //Doesn't work in 5 dollar DigitalOcean droplets
            Parallel.Invoke(
                async() => op.Allianz  = await oshcApiHandler.AllianzQuoteHandler(bq),
                async() => op.Nib      = await oshcApiHandler.NibApiHandler(bq),
                async() => op.Ahm      = await oshcApiHandler.AhmQuoteHandler(bq),
                async() => op.Medibank = await oshcApiHandler.MedibankQuoteHandler(bq)
                );


            var context = new mbsContext();



            context.OshcQuote.Add(op);
            context.SaveChanges();
            Console.WriteLine($"OP class: {stopwatch.Elapsed.ToString()} has elapsed");
            //stopwatch.Stop();
            return(1);
        }