Ejemplo n.º 1
0
        private async Task <string> GetTokenFromIndus()
        {
            DP_TPEntities db     = new DP_TPEntities();
            string        uri    = "https://fastag.gitechnology.in/indusindAPI/api/Authentication/RequestToken";
            var           client = new RestClient(uri);

            client.Timeout = -1;
            var    request   = new RestRequest(Method.GET);
            string nonce     = OAuthBase.GenerateNonce();
            string timeStamp = OAuthBase.GenerateTimeStamp();
            string sig       = OAuthBase.GenerateSignature(new Uri(uri), Consumerkey, ConsumerSecret, null, null, "GET", timeStamp, nonce, OAuthBase.HMACSHA1SignatureType);

            sig = HttpUtility.UrlEncode(sig);
            string authString = String.Format(@"OAuth oauth_consumer_key=""{0}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{1}"",oauth_nonce=""{2}"",oauth_version=""1.0"",oauth_signature=""{3}""""", Consumerkey, timeStamp, nonce, sig);

            request.AddHeader("Authorization", authString);
            request.AddHeader("Connection", "Keep-Alive");
            IRestResponse response = client.Execute(request);

            Console.WriteLine(response.Content);
            TokenResponse    json = JsonConvert.DeserializeObject <TokenResponse>(response.Content);
            var              x    = json.ResponseData;// this extracts the encrypted requesttoken;
            string           s1   = EncryptionsUtility.AES_DECRYPT(x, AESkey);
            clsTokenResponse obj  = JsonConvert.DeserializeObject <clsTokenResponse>(s1);

            Console.WriteLine(obj.ResponseContent.Token);
            db.IndusInd_Token_Secrete.Add(new IndusInd_Token_Secrete()
            {
                CreateDate = DateTime.Now, Token = obj.ResponseContent.Token, TokenSecrete = obj.ResponseContent.TokenSecret
            });
            db.SaveChanges();
            return(s1);
        }
Ejemplo n.º 2
0
        public static clsKeyValue GetKeys()
        {
            DP_TPEntities  db  = new DP_TPEntities();
            JwtAuthManager jwt = new JwtAuthManager();


            string Key              = db.AppKeys.Where(x => x.vKey == "key").FirstOrDefault().vvalue;
            string XIBMClientId     = db.AppKeys.Where(x => x.vKey == "XIBMClientId").FirstOrDefault().vvalue;
            string easebuzzsalt     = db.AppKeys.Where(x => x.vKey == "easebuzzsalt").FirstOrDefault().vvalue;
            string easebuzzkey      = db.AppKeys.Where(x => x.vKey == "easebuzzkey").FirstOrDefault().vvalue;
            string easebuzzenv      = db.AppKeys.Where(x => x.vKey == "easebuzzenv").FirstOrDefault().vvalue;
            string payUsalt         = db.AppKeys.Where(x => x.vKey == "payUsalt").FirstOrDefault().vvalue;
            string payUkey          = db.AppKeys.Where(x => x.vKey == "payUkey").FirstOrDefault().vvalue;
            string payUzenv         = db.AppKeys.Where(x => x.vKey == "payUenv").FirstOrDefault().vvalue;
            string XIBMClientSecret = db.AppKeys.Where(x => x.vKey == "XIBMClientSecret").FirstOrDefault().vvalue;
            string SessionKey       = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
            string AxisSetuAPIURL   = db.AppKeys.Where(x => x.vKey == "AxisSetuAPIURL").FirstOrDefault().vvalue;
            string JWT              = "Bearer " + jwt.GenerateJWTToken();

            return(new clsKeyValue()
            {
                Key = Key, XIBMClientId = XIBMClientId,
                XIBMClientSecret = XIBMClientSecret, SessionID = SessionKey, JWT = JWT,
                easebuzzenv = easebuzzenv,
                easebuzzkey = easebuzzkey,
                easebuzzsalt = easebuzzsalt,
                AxisSetuAPIURL = AxisSetuAPIURL,
                payUsalt = payUsalt,
                payUkey = payUkey,
                payUenv = payUzenv
            });
        }
Ejemplo n.º 3
0
        public static string getheader(string strurl, string methodtype)
        {
            string nonce     = OAuthBase.GenerateNonce();
            string timeStamp = OAuthBase.GenerateTimeStamp();

            DP_TPEntities          db        = new DP_TPEntities();
            IndusInd_Token_Secrete lastestts = db.IndusInd_Token_Secrete.ToList().LastOrDefault();

            string sig = OAuthBase.GenerateSignature(new Uri(strurl), Consumerkey, ConsumerSecret, lastestts.Token, lastestts.TokenSecrete, methodtype, timeStamp, nonce, OAuthBase.HMACSHA1SignatureType);

            sig = HttpUtility.UrlEncode(sig);
            string authString2 = String.Format(@"OAuth oauth_consumer_key=""{0}"",oauth_nonce=""{1}"",oauth_signature=""{2}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{3}"",oauth_token=""{4}"",oauth_version=""1.0""", Consumerkey, nonce, sig, timeStamp, lastestts.Token);


            return(authString2);
        }
Ejemplo n.º 4
0
        private DALSingletonAppSetting()
        {
            DP_TPEntities dp = new DP_TPEntities();

            ak = dp.AppKeys.ToList();
        }
Ejemplo n.º 5
0
        public clsOTPValidationResponse MethodOTPValidationRequest(Bank_OTPValidationAPI bov)
        {
            DP_TPEntities db  = new DP_TPEntities();
            clsKeyValue   ckv = EncryptionLibrary.GetKeys();

            // bov.otpReferenceId = ckv.SessionID.Substring(0,19);

            try
            {
                //db.Bank_OTPValidationAPI.Add(bov);
                //db.SaveChanges();

                _clsNhaicchvalidateotprequest = new clsNhaicchvalidateotprequest();
                _clsNhaicchvalidateotprequest.NHAICCHValidateOTPRequest           = new Nhaicchvalidateotprequest();
                _clsNhaicchvalidateotprequest.NHAICCHValidateOTPRequest.SubHeader = new Subheader()
                {
                    channelId             = "DIGI",
                    requestUUID           = bov.otpReferenceId,
                    serviceRequestId      = "AE.NHAI.OTP.ESB.001",
                    serviceRequestVersion = "1.0"
                };
                var jsonString = JsonConvert.SerializeObject(bov);

                _clsNhaicchvalidateotprequest.NHAICCHValidateOTPRequest.NHAICCHValidateOTPRequestBodyEncrypted = EncryptionLibrary.encrypt(jsonString, ckv.Key);
                var client = new RestClient(ckv.AxisSetuAPIURL + "/api/gateway/api/v1/fastag/otp-validation");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("X-IBM-Client-Id", ckv.XIBMClientId);
                request.AddHeader("X-IBM-Client-Secret", ckv.XIBMClientSecret);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("Authorization", ckv.JWT);

                var requeststr = JsonConvert.SerializeObject(_clsNhaicchvalidateotprequest);
                //Console.WriteLine("Request to API " + requeststr.ToString());
                request.AddParameter("application/json", requeststr.ToString(), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                //Console.WriteLine("AS Customer Dedupe Encrypted Reponse" + response.Content);

                APIException apierror = JsonConvert.DeserializeObject <APIException>(response.Content);
                clsNhaicchvalidateotpresponse json = JsonConvert.DeserializeObject <clsNhaicchvalidateotpresponse>(response.Content);

                string ser = string.Empty;
                if (apierror.httpCode != 200 && apierror.httpCode != 0) //503
                {
                    ser = JsonConvert.SerializeObject(apierror);
                    covr.isOTPValidated = false;
                }
                else if (response.Content != string.Empty)
                {
                    ser  = EncryptionLibrary.decrypt(json.NHAICCHValidateOTPResponse.NHAICCHValidateOTPResponseBodyEncrypted, ckv.Key);
                    covr = JsonConvert.DeserializeObject <clsOTPValidationResponse>(ser);
                    //db.Bank_OTPValidationAPI.Where(o=>o.)
                    //db.Bank_OTPGenerationResponse.Add(covr);
                    //db.SaveChanges();
                }
                else
                {
                    ser = "Error";
                }



                db.AxisSetuAPILoggers.Add(new AxisSetuAPILogger()
                {
                    RequestGuid       = ckv.SessionID,
                    request           = jsonString.ToString(),
                    requestEncrypted  = requeststr,
                    responseEncrypted = response.Content,
                    response          = JsonConvert.SerializeObject(covr)
                });
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                covr.isOTPValidated = false;
                return(covr);
            }

            return(covr);
        }
Ejemplo n.º 6
0
        public Bank_RechargeResponse MethodRechargeWalletRequest(Bank_RechargeRequest brr)
        {
            DP_TPEntities      db    = new DP_TPEntities();
            clsKeyValue        ckv   = EncryptionLibrary.GetKeys();
            string             vguid = Convert.ToString(Guid.NewGuid());
            clsRechargerequest crg   = new clsRechargerequest();

            crg.RechargeRequest = new Rechargerequest();
            Bank_RechargeResponse brra = new Bank_RechargeResponse();

            try
            {
                crg.RechargeRequest.SubHeader = new Subheader()
                {
                    channelId             = "DIGI",
                    requestUUID           = vguid,
                    serviceRequestId      = "RECHARGE",
                    serviceRequestVersion = "1.0"
                };

                var jsonString = JsonConvert.SerializeObject(brr);



                crg.RechargeRequest.RechargeRequestBodyEncrypted = EncryptionLibrary.encrypt(jsonString, ckv.Key);

                var client = new RestClient(ckv.AxisSetuAPIURL + "/api/gateway/api/v1/fastag/recharge");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("X-IBM-Client-Id", ckv.XIBMClientId);
                request.AddHeader("X-IBM-Client-Secret", ckv.XIBMClientSecret);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("Authorization", ckv.JWT);

                var requeststr = JsonConvert.SerializeObject(crg);
                //Console.WriteLine("Request to API " + requeststr.ToString());
                request.AddParameter("application/json", requeststr.ToString(), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                //Console.WriteLine("AS Customer Dedupe Encrypted Reponse" + response.Content);

                APIException        apierror = JsonConvert.DeserializeObject <APIException>(response.Content);
                clsRechargeresponse json     = JsonConvert.DeserializeObject <clsRechargeresponse>(response.Content);

                string ser = string.Empty;
                if (apierror.httpCode != 200 && apierror.httpCode != 0) //503
                {
                    ser = JsonConvert.SerializeObject(apierror);
                    brra.statusMessage = apierror.moreInformation + " | " + apierror.httpMessage;
                }
                else if (response.Content != string.Empty)
                {
                    ser  = EncryptionLibrary.decrypt(json.RechargeResponse.RechargeResponseBodyEncrypted, ckv.Key);
                    brra = JsonConvert.DeserializeObject <Bank_RechargeResponse>(ser);
                    db.Bank_RechargeResponse.Add(brra);
                    db.SaveChanges();
                }
                else
                {
                    ser = "Error";
                }

                Console.WriteLine("API Plan Reponse" + ser);

                db.AxisSetuAPILoggers.Add(new AxisSetuAPILogger()
                {
                    RequestGuid       = ckv.SessionID,
                    request           = jsonString.ToString(),
                    subheaderMethod   = crg.RechargeRequest.SubHeader.serviceRequestId,
                    requestEncrypted  = requeststr,
                    responseEncrypted = response.Content,
                    response          = JsonConvert.SerializeObject(ser)
                });
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                brra.statusMessage = ex.Message;
                return(brra);
            }
            return(brra);
        }
        public Bank_RechargeStatusEnquiryResponse MethodclsWalletRequestStatus(Bank_RechargeStatusEnquiry brse)
        {
            DP_TPEntities db  = new DP_TPEntities();
            clsKeyValue   ckv = EncryptionLibrary.GetKeys();

            brse.uniquerefNo = ckv.SessionID.Substring(0, 19);

            db.Bank_RechargeStatusEnquiry.Add(brse);
            db.SaveChanges();

            ClsRStatusenquiryrequest Rser = new ClsRStatusenquiryrequest();

            Rser.StatusEnquiryRequest           = new RStatusenquiryrequest();
            Rser.StatusEnquiryRequest.SubHeader = new Subheader()
            {
                channelId             = "DIGI",
                requestUUID           = ckv.SessionID,
                serviceRequestId      = "RECHARGE-STATUS-ENQUIR",
                serviceRequestVersion = "1.0"
            };

            var jsonString = JsonConvert.SerializeObject(brse);

            Rser.StatusEnquiryRequest.StatusEnquiryRequestBodyEncrypted = EncryptionLibrary.encrypt(jsonString, ckv.Key);
            var client = new RestClient(ckv.AxisSetuAPIURL + "/api/gateway/api/v1/fastag/enquiry");

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("X-IBM-Client-Id", ckv.XIBMClientId);
            request.AddHeader("X-IBM-Client-Secret", ckv.XIBMClientSecret);
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("Authorization", ckv.JWT);

            var requeststr = JsonConvert.SerializeObject(Rser);

            request.AddParameter("application/json", requeststr.ToString(), ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            //Console.WriteLine("AS Customer Dedupe Encrypted Reponse" + response.Content);

            APIException apierror          = JsonConvert.DeserializeObject <APIException>(response.Content);
            clsRStatusenquiryresponse json = JsonConvert.DeserializeObject <clsRStatusenquiryresponse>(response.Content);

            string ser = string.Empty;

            if (apierror.httpCode != 200 && apierror.httpCode != 0) //503
            {
                ser = JsonConvert.SerializeObject(apierror);
                brser.statusMessage = apierror.moreInformation + " | " + apierror.httpMessage;;
                brser.statusCode    = apierror.httpCode.ToString();
            }
            else if (response.Content != string.Empty)
            {
                ser   = EncryptionLibrary.decrypt(json.StatusEnquiryResponse.StatusEnquiryResponseBodyEncrypted, ckv.Key);
                brser = JsonConvert.DeserializeObject <Bank_RechargeStatusEnquiryResponse>(ser);

                db.Bank_RechargeStatusEnquiryResponse.Add(brser);
                db.SaveChanges();
            }
            else
            {
                ser = "Error";
            }

            Console.WriteLine("API Plan Reponse" + ser);

            db.AxisSetuAPILoggers.Add(new AxisSetuAPILogger()
            {
                RequestGuid       = ckv.SessionID,
                request           = jsonString.ToString(),
                subheaderMethod   = Rser.StatusEnquiryRequest.SubHeader.serviceRequestId,
                requestEncrypted  = requeststr,
                responseEncrypted = response.Content,
                response          = JsonConvert.SerializeObject(brser)
            });
            db.SaveChanges();

            return(brser);
        }
Ejemplo n.º 8
0
        // this function is required to initiate payment
        public string initiatePaymentAPI(string aAmount, String Firstname, String Email, String Phone, String Productinfo, String Surl, String Furl, String Txnid)
        {
            env = ckv.easebuzzenv;
            string[] hashVarsSeq;
            string   hash_string = string.Empty;
            string   saltvalue   = ckv.easebuzzsalt;
            string   amount      = aAmount;
            string   firstname   = Firstname;
            string   email       = Email;
            string   phone       = Phone;
            string   productinfo = Productinfo;
            string   surl        = Surl;
            string   furl        = Furl;
            string   udf1        = "";
            string   udf2        = "";
            string   udf3        = "";
            string   udf4        = "";
            string   udf5        = "";

            // Generate transaction ID -> make sure this is unique for all transactions
            Random rnd     = new Random();
            string strHash = Easebuzz_Generatehash512(rnd.ToString() + DateTime.Now);

            //txnid = strHash.ToString().Substring(0, 20);
            txnid = Txnid;

            string paymentUrl = getURL();

            // Get configs from web config
            easebuzz_action_url = paymentUrl; // + "/pay/secure";

            // generate hash table
            System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
            data.Add("txnid", txnid);
            data.Add("key", ckv.easebuzzkey);
            string AmountForm = Convert.ToDecimal(amount.Trim()).ToString("g29");// eliminating trailing zeros

            amount = AmountForm;
            data.Add("amount", amount);
            data.Add("firstname", firstname.Trim());
            data.Add("email", email.Trim());
            data.Add("phone", phone.Trim());
            data.Add("productinfo", productinfo.Trim());
            data.Add("surl", surl.Trim());
            data.Add("furl", furl.Trim());
            data.Add("udf1", udf1.Trim());
            data.Add("udf2", udf2.Trim());
            data.Add("udf3", udf3.Trim());
            data.Add("udf4", udf4.Trim());
            data.Add("udf5", udf5.Trim());


            // generate hash
            hashVarsSeq = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10".Split('|'); // spliting hash sequence from config
            hash_string = "";
            foreach (string hash_var in hashVarsSeq)
            {
                hash_string = hash_string + (data.ContainsKey(hash_var) ? data[hash_var].ToString() : "");
                hash_string = hash_string + '|';
            }
            hash_string += salt;                                            // appending SALT
            gen_hash     = Easebuzz_Generatehash512(hash_string).ToLower(); //generating hash
            data.Add("hash", gen_hash);
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var client  = new RestClient("https://pay.easebuzz.in/payment/initiateLink");
            var request = new RestRequest(Method.POST);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            string postdata = "firstname=" + firstname + "&amount=" + amount + "&email=" + email + "&productinfo=FastagRecharge&phone=" + phone + "&surl=https://payment.tollpay.in/success.aspx&furl=https://payment.tollpay.in/success.aspx&txnid=" + txnid + "&key=" + ckv.easebuzzkey + "&udf1=&udf2=&udf3=&udf4=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=" + gen_hash;

            request.AddParameter("application/x-www-form-urlencoded", postdata, ParameterType.RequestBody);
            IRestResponse   response = client.Execute(request);
            clsRespEaseBuzz obj      = JsonConvert.DeserializeObject <clsRespEaseBuzz>(response.Content);

            if (obj.status == 1)
            {
                DP_TPEntities          db  = new DP_TPEntities();
                PaymentGatewayResponse pgr = new PaymentGatewayResponse();
                pgr.firstname   = firstname;
                pgr.email       = email;
                pgr.CreatedDate = DateTime.Now;
                pgr.phone       = phone;
                pgr.amount      = Convert.ToDecimal(amount);
                pgr.txnid       = txnid;
                db.PaymentGatewayResponses.Add(pgr);
                db.SaveChanges();
                string strForm = easebuzz_action_url + obj.data;                     //Easebuzz_PreparePOSTForm(easebuzz_action_url, data);
                return(strForm);
            }
            else
            {
                DP_TPEntities          db  = new DP_TPEntities();
                PaymentGatewayResponse pgr = new PaymentGatewayResponse();
                pgr.firstname   = firstname;
                pgr.email       = email;
                pgr.CreatedDate = DateTime.Now;
                pgr.phone       = phone;
                pgr.amount      = Convert.ToDecimal(amount);
                pgr.txnid       = txnid;
                db.PaymentGatewayResponses.Add(pgr);
                db.SaveChanges();
                return(response.Content);
            }
        }
Ejemplo n.º 9
0
        public Tollcal GetTollPlaza(string source, string destination, string vehicletype, string journey)
        {
            bool    flag     = false;
            Tollcal response = new Tollcal();

            if (flag)
            {
                #region Sagar Code
                WebClient wb     = new WebClient();
                string    strurl = "http://tis.nhai.gov.in/UploadHandler.ashx?Up=3&Source=" + source + "&Destination=" + destination;

                string result = wb.DownloadString(strurl);
                //18.3313849,73.8525197$17.810312,73.971381$$113 km!2 hours 13 mins
                List <string>    tollplazza      = result.Split('$').ToList();
                DP_TPEntities    db              = new DP_TPEntities();
                List <TollPlaza> lsttollinrounte = new List <TollPlaza>();
                User_Trips       ut              = new User_Trips();
                ut.tripStartLocation = source;
                ut.tripEndLocation   = destination;
                Random random = new Random();
                int    numb   = random.Next(1, 31) % 31;
                if (numb != 0)
                {
                    ut.tripDate   = new DateTime(2019, 8, numb);
                    ut.tripStatus = "a";
                    ut.userid     = 1;
                }
                foreach (var item in tollplazza)
                {
                    if (item.Contains(','))
                    {
                        List <string> latlng = item.Split(',').ToList();
                        double        dlat   = Convert.ToDouble(latlng[0]);
                        lsttollinrounte.Add(db.TollPlazas.Where(l => l.lat == dlat).FirstOrDefault());
                    }
                }
                dynamic orderTotals = 0.0;
                //let orderTotals;
                //var orderTotals;
                List <TollPlazaRateByVehicleTypes> LstTPRBV = new List <TollPlazaRateByVehicleTypes>();

                switch (vehicletype)
                {
                case "Bus":
                    orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_bus_multi)).FirstOrDefault();
                    LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_bus_multi
                    }).ToList();
                    break;

                case "car":
                    if (journey == "multi")
                    {
                        orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_car_multi)).FirstOrDefault();
                        LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_car_multi
                        }).ToList();
                    }
                    else
                    {
                        orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => Convert.ToDecimal(item.rates_car_single))).FirstOrDefault();
                        LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_car_single
                        }).ToList();
                    }
                    break;

                case "sixaxle":
                    orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_four_six_axle_multi)).FirstOrDefault();
                    LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_four_six_axle_multi
                    }).ToList();
                    break;

                case "hcm":
                    orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_hcm_multi)).FirstOrDefault();
                    LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_hcm_multi
                    }).ToList();
                    break;

                case "lcv":
                    if (journey == "multi")
                    {
                        orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_lcv_multi)).FirstOrDefault();
                        LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_lcv_multi
                        }).ToList();
                    }
                    else
                    {
                        orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => Convert.ToDecimal(item.rates_lcv_single))).FirstOrDefault();
                        LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_lcv_single
                        }).ToList();
                    }

                    break;

                case "multaxle":
                    orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_multiaxle_multi)).FirstOrDefault();
                    LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_multiaxle_multi
                    }).ToList();
                    break;

                case "sevenaxle":
                    orderTotals = lsttollinrounte.GroupBy(i => 1).Select(g => g.Sum(item => item.rates_seven_plus_axle_multi)).FirstOrDefault();
                    LstTPRBV    = lsttollinrounte.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, lat = x.lat, lon = x.lon, Rate = x.rates_seven_plus_axle_multi
                    }).ToList();
                    break;

                default:
                    Console.WriteLine("Default case");
                    break;
                }

                // Tollcal response = new Tollcal();

                response.tollplaza = LstTPRBV;
                response.totalcost = (double)orderTotals;
                return(response);

                #endregion
            }
            else
            {
                string src  = source;
                string dest = destination;
                string vt   = vehicletype;
                string tt   = journey;
                //TollPlazaServiceSoapClient proxy = new TollPlazaServiceSoapClient();
                //List<string> names= proxy.AutoCompleteLocation("pu").ToList();
                WebClient wb     = new WebClient();
                string    result = string.Empty;
                try
                {
                    result = db.RouteTollsQueries.Where(r => r.src.Contains(src) && r.dest.Contains(dest)).FirstOrDefault().routetolls;
                }
                catch (Exception ex)
                {
                    if (result == string.Empty)
                    {
                        string strurl = "http://tis.nhai.gov.in/UploadHandler.ashx?Up=3&Source=" + src + "&Destination=" + dest;
                        result = wb.DownloadString(strurl);
                        db.RouteTollsQueries.Add(new RouteTollsQuery()
                        {
                            src = src, dest = dest, routeactive = "a", routetolls = result
                        });
                        db.SaveChanges();
                    }
                }


                List <getTripPrices_Result> lsttollplazz = db.getTripPrices(result).ToList();

                List <TollPlazaRateByVehicleTypes> LstTPRBV = new List <TollPlazaRateByVehicleTypes>();

                switch (vt)
                {
                case "Bus":

                    LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_bus_multi
                    }).ToList();
                    break;

                case "Car":
                    if (journey == "multi")
                    {
                        LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_car_multi
                        }).ToList();
                    }
                    else
                    {
                        LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_car_single
                        }).ToList();
                    }
                    break;

                case "Sixaxle":

                    LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_four_six_axle_multi
                    }).ToList();
                    break;

                case "HCM":

                    LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_hcm_multi
                    }).ToList();
                    break;

                case "LCV":
                    if (journey == "multi")
                    {
                        LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_lcv_multi
                        }).ToList();
                    }
                    else
                    {
                        LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                        {
                            id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_lcv_single
                        }).ToList();
                    }

                    break;

                case "Multaxle":

                    LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_multiaxle_multi
                    }).ToList();
                    break;

                case "Sevenaxle":

                    LstTPRBV = lsttollplazz.Select(x => new TollPlazaRateByVehicleTypes()
                    {
                        id = x.id, name = x.name, lat = x.lat, lon = x.lon, Rate = x.rates_seven_plus_axle_multi
                    }).ToList();
                    break;

                default:
                    // Console.WriteLine("Default case");
                    break;
                }

                List <TollRateCard> orderTotals = lsttollplazz
                                                  .GroupBy(i => 1)
                                                  .Select(g => new TollRateCard
                {
                    cnt = g.Count(),
                    rates_car_single              = g.Sum(item => item.rates_car_single),
                    rates_car_multi               = g.Sum(item => item.rates_car_multi),
                    rates_car_monthly             = g.Sum(item => item.rates_car_monthly),
                    rates_bus_multi               = g.Sum(item => item.rates_bus_multi),
                    rates_bus_monthly             = g.Sum(item => item.rates_bus_monthly),
                    rates_four_six_axle_single    = g.Sum(item => item.rates_four_six_axle_single),
                    rates_four_six_axle_multi     = g.Sum(item => item.rates_four_six_axle_multi),
                    rates_four_six_axle_monthly   = g.Sum(item => item.rates_four_six_axle_monthly),
                    rates_seven_plus_axle_single  = g.Sum(item => item.rates_seven_plus_axle_single),
                    rates_seven_plus_axle_multi   = g.Sum(item => item.rates_seven_plus_axle_multi),
                    rates_seven_plus_axle_monthly = g.Sum(item => item.rates_seven_plus_axle_monthly),
                    rates_hcm_single              = g.Sum(item => item.rates_hcm_single),
                    rates_hcm_multi               = g.Sum(item => item.rates_hcm_multi),
                    rates_hcm_monthly             = g.Sum(item => item.rates_hcm_monthly),
                    rates_lcv_single              = g.Sum(item => item.rates_lcv_single),
                    rates_lcv_multi               = g.Sum(item => item.rates_lcv_multi),
                    rates_lcv_monthly             = g.Sum(item => item.rates_lcv_monthly),
                    rates_multiaxle_single        = g.Sum(item => item.rates_multiaxle_single),
                    rates_multiaxle_multi         = g.Sum(item => item.rates_multiaxle_multi),
                    rates_multiaxle_monthly       = g.Sum(item => item.rates_multiaxle_monthly)
                }).ToList();


                double?tollamt = 0;
                switch (vt)
                {
                case "Car":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_car_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_car_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_car_monthly;
                    }
                    break;

                case "LCV":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_lcv_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_lcv_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_lcv_monthly;
                    }
                    break;

                case "Bus":
                    if (tt.ToLower() == "single")
                    {     //tollamt = orderTotals[0].rates_bus_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_bus_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_bus_monthly;
                    }
                    break;

                case "Multiaxle":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_multiaxle_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_multiaxle_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_multiaxle_monthly;
                    }
                    break;

                case "HCM":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_hcm_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_hcm_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_hcm_monthly;
                    }
                    break;

                case "Four_six_axle":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_four_six_axle_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_four_six_axle_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_four_six_axle_monthly;
                    }
                    break;

                case "Seven_plus_axle":
                    if (tt.ToLower() == "single")
                    {
                        tollamt = orderTotals[0].rates_seven_plus_axle_single;
                    }
                    else if (tt.ToLower() == "multi")
                    {
                        tollamt = orderTotals[0].rates_seven_plus_axle_multi;
                    }
                    else
                    {
                        tollamt = orderTotals[0].rates_seven_plus_axle_monthly;
                    }
                    break;

                default: break;
                }


                List <TollPlaza> lsttp = new List <TollPlaza>();
                foreach (var item in lsttollplazz)
                {
                    TollPlaza tp = new TollPlaza();
                    tp.id   = item.id;
                    tp.name = item.name;
                    tp.lat  = item.lat;
                    tp.lon  = item.lon;
                    lsttp.Add(tp);
                    //response.tollplaza.Add(tp);

                    #region mapcode
                    //public string name { get; set; }
                    //public Nullable<double> lat { get; set; }
                    //public Nullable<double> lon { get; set; }
                    //public Nullable<System.DateTime> fee_effective_date { get; set; }
                    //public Nullable<double> rates_car_single { get; set; }
                    //public Nullable<double> rates_car_multi { get; set; }
                    //public Nullable<double> rates_car_monthly { get; set; }
                    //public Nullable<double> rates_lcv_single { get; set; }
                    //public Nullable<double> rates_lcv_multi { get; set; }
                    //public Nullable<double> rates_lcv_monthly { get; set; }
                    //public Nullable<double> rates_bus_multi { get; set; }
                    //public Nullable<double> rates_bus_monthly { get; set; }
                    //public Nullable<double> rates_multiaxle_single { get; set; }
                    //public Nullable<double> rates_multiaxle_multi { get; set; }
                    //public Nullable<double> rates_multiaxle_monthly { get; set; }
                    //public Nullable<double> rates_hcm_single { get; set; }
                    //public Nullable<double> rates_hcm_multi { get; set; }
                    //public Nullable<double> rates_hcm_monthly { get; set; }
                    //public Nullable<double> rates_four_six_axle_single { get; set; }
                    //public Nullable<double> rates_four_six_axle_multi { get; set; }
                    //public Nullable<double> rates_four_six_axle_monthly { get; set; }
                    //public Nullable<double> rates_seven_plus_axle_single { get; set; }
                    //public Nullable<double> rates_seven_plus_axle_multi { get; set; }
                    //public Nullable<double> rates_seven_plus_axle_monthly { get; set; }

                    #endregion
                }
                response.tollplaza = LstTPRBV;
                response.totalcost = (double)tollamt;
                return(response);
            }
        }