Пример #1
0
        public int InsertData()
        {
            // Scaffold - DbContext "server=xx.xx.xx.xx;port=3306;user=root;password=*************;database=mbs" MySql.Data.EntityFrameworkCore - f
            var xd = new OshcQuote();

            return(0);
        }
        /// <summary>
        /// Quote is fetched from db because of the response time limitation.
        /// Check cronjob folder for the cronjob that fetches and save prices automatically
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public string OshcGetQuote(DflowWebhookRequest request)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var bq    = new BaseQuote();
            var cover = "";

            bq.duration = (int)(request.QueryResult.Parameters.Duration.Value ?? 0);
            if (request.QueryResult.Parameters.Duration.DurationDuration == "year")
            {
                bq.duration = bq.duration * 12;
            }
            var child = request.QueryResult.Parameters.Child.ToLower();
            var adult = request.QueryResult.Parameters.Partner.ToLower();

            if (child == "no" && adult == "no")
            {
                cover = "Single";
            }
            else if (child == "no" && adult == "yes")
            {
                cover = "Couple";
            }
            else if (child == "yes" && adult == "yes")
            {
                cover = "Family";
            }
            else if (child == "yes" && adult == "no")
            {
                cover = "Single Parent";
            }

            string model = "";

            Console.WriteLine($"Sending to Handler: {stopwatch.Elapsed.ToString()} has elapsed");
            mbsContext mbs = new mbsContext();

            try
            {
                OshcQuote quote = mbs.OshcQuote.Where(e => (e.Covertype == cover) && (e.Duration == bq.duration)).OrderByDescending(a => a.Date)
                                  .Select(p => p).FirstOrDefault();;
                Console.WriteLine($"OP class: {stopwatch.Elapsed.ToString()} has elapsed");
                model = $"You will need a {cover} cover.\n" +
                        $"For {bq.duration} months, this is the quote I have fetched:\n" +
                        $"1. Allianz OSHC: ${quote.Allianz}AUD \n" +
                        $"2. Medibank OSHC: ${quote.Medibank}AUD \n" +
                        $"3. Nib OSHC: ${quote.Nib}AUD \n" +
                        $"4. AHM OSHC: ${quote.Ahm}AUD \n" +
                        $"**This quote was fetched on {quote.Date.ToString("g", new CultureInfo("en-AU"))} AEST. It will be updated on {quote.Date.AddDays(1).ToString("d", new CultureInfo("en-AU"))} at 6:00 AM AEST";
                stopwatch.Stop();
            }
            catch (Exception e)
            {
                model = "Sorry, but something went wrong. Please try later";
            }

            return(model);
        }
Пример #3
0
        public async Task <OshcQuote> OshcGetQuote(BotQuoteRequest quoteRequest)
        {
            string Covertype = quoteRequest.CoverType;
            int    duration  = quoteRequest.Duration;
            var    bq        = new BaseQuote
            {
                duration = duration
            };

            var op = new OshcQuote
            {
                Date = DateTime.UtcNow.AddHours(10).ToString("f",
                                                             CultureInfo.CreateSpecificCulture("en-AU")) + " AEST",
                Duration = duration
            };

            // Generating ID using covertype, duration and datetime
            op.Id = Covertype + "-" + duration + "-" + op.Date;
            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 droplet

            op.Allianz = await oshcApiHandler.AllianzQuoteHandler(bq);

            op.Nib = await oshcApiHandler.AllianzQuoteHandler(bq);

            op.Ahm = await oshcApiHandler.AhmQuoteHandler(bq);

            op.Medibank = await oshcApiHandler.MedibankQuoteHandler(bq);



            //stopwatch.Stop();
            return(op);
        }
Пример #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);
        }