
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Configuration;
using CLS_DL;
using System.Text;
using System.Threading.Tasks;

namespace CLS_BL
{
    public class BL_API
    {

        JSONTODATATABLE DTJSONWEBTABLELIST = new JSONTODATATABLE();
        DataTable DTWEBTABLELIST = new DataTable();
        //BL_SELECT objSEL = new BL_SELECT();
        string FirstName = string.Empty;
        string UserName = string.Empty;
        string BarerToken = string.Empty;

        string BaseUrl = ConfigurationManager.ConnectionStrings["API_BaseURL"].ConnectionString;

        //need to encrypt after development and testing
        //string sXeroTokenURL = "https://identity.xero.com/connect/token";
        //string sXeroURL = "https://api.xero.com/api.xro/2.0";
        //string sXeroAPIKey = "A1572E0EACAF43768A36E86B747950AF";
        //string sXeroSecret = "R2WFLswpGUUftNiRs2etfpwufCNIUou44jzA9lwRaQBXHHTO";

        #region  AUTHENTICATION GET METHODS 
        /// <summary>
        ///  This Function Uses To Get the BarerToken 
        /// </summary>
        /// <returns></returns>
        public String GetBarerToken()
        {

            var client5 = new RestSharp.RestClient("" + BaseUrl + "/Users/authenticate");
            client5.Timeout = -1;
            var request5 = new RestRequest(Method.POST);
            request5.AddHeader("Content-Type", "application/json");
            request5.AddParameter("application/json", "{\r\n    \"username\": \"test\",\r\n    \"password\": \"test\"\r\n}", ParameterType.RequestBody);
            IRestResponse response5 = client5.Execute(request5);
            Console.WriteLine(response5.Content);

            // Reading Json Data : 

            var ReadData = JObject.Parse(response5.Content.ToString());

            JArray ReadArray = new JArray();
            ReadArray.Add(ReadData);

            foreach (JToken ReadItem in ReadArray)
            {

                FirstName = ReadItem["firstName"].ToString();
                UserName = ReadItem["username"].ToString();
                BarerToken = ReadItem["token"].ToString();




            }

            return BarerToken;

        }
        #endregion

        #region WEBTRANS  API POST 

        /// <summary>
        ///  This API Call tends POST data to database 
        /// </summary>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        public string APICALL_Create(string dbname, string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransaction/Create?clientDb='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            //request.AddParameter("application/json", "{\r\n   \"order_id\":1,\r\n   \"Operator\":\"Mobile\",\r\n   \"table_no\":\"101\",\r\n   \"Pax\":0,\r\n   \"PaymentType\":\"None\",\r\n   \"TotalPayment\":0,\r\n   \"Name\":\"Guest\",\r\n   \"Mobile\":12345678,\r\n   \"Address\":\"\",\r\n   \"Notes\":\"   \",\r\n   \"order_items\":[\r\n      {\r\n         \"product_id\":3,\r\n         \"product_barcode\":\"A02\",\r\n         \"product_price\":10.9000,\r\n         \"quantity\":1,\r\n         \"item_id\":1,\r\n         \"remarks\":[\r\n            {\r\n               \"item_id\":1,\r\n               \"CondimentID\":1,\r\n               \"remarkName\":\" Black Pepper \"\r\n            },\r\n            {\r\n               \"item_id\":1,\r\n               \"CondimentID\":2,\r\n               \"remarkName\":\" More Sauce  \"\r\n            }\r\n         ],\r\n         \"is_set_meal\":0,\r\n         \"manualRemark\":\"  \"\r\n      },\r\n      {\r\n         \"product_id\":4,\r\n         \"product_barcode\":\"A03\",\r\n         \"product_price\":10.9000,\r\n         \"quantity\":1,\r\n         \"item_id\":2,\r\n         \"remarks\":[\r\n            {\r\n               \"item_id\":2,\r\n               \"CondimentID\":1,\r\n               \"remarkName\":\" 3rd Set \"\r\n            },\r\n            {\r\n               \"item_id\":2,\r\n               \"CondimentID\":2,\r\n               \"remarkName\":\" 4th Set  \"\r\n            },\r\n          ],\r\n         \"is_set_meal\":0,\r\n         \"manualRemark\":\"Test 1\"\r\n      }\r\n   ]\r\n}", ParameterType.RequestBody);
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);
            //  Console.WriteLine(response.Content);

            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;



        }

        public string APICALLV2_Create(string dbname, string BarToken, string JSONVALUE) //JOHN ADDED ON 10-JUNE-2021 FOR Version 2(WebTrans(Email,PickupTime) WebTransDetail(Pricetype))
        {
            var API_Version = System.Configuration.ConfigurationManager.AppSettings["API_Version"];
            string sApiResponse = string.Empty;
            if (API_Version == "2")
            {
                var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransactionV2/Create?clientDb='" + dbname + "' ");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", BarerToken);
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
                var response = client.Execute(request);
                sApiResponse = response.IsSuccessful.ToString();

            }
            else if (API_Version == "3")
            {
                var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransactionV3/Create?clientDb='" + dbname + "' ");
                //var client = new RestSharp.RestClient("http://localhost:61760/api/WebTransactionV3/Create?clientDb='" + dbname + "' ");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", BarerToken);
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
                var response = client.Execute(request);
                sApiResponse = response.IsSuccessful.ToString();
            }
            else if (API_Version == "4") //OrderID from int to char
            {
                string sAPIResponse = string.Empty;
                var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransactionV4/Create?clientDb='" + dbname + "'");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", BarerToken);
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
                var response = client.Execute(request);
                sAPIResponse = response.IsSuccessful.ToString();
                return sAPIResponse;
            }
            return sApiResponse;

        }

        public string APICALLV4_Create(string dbname, string BearerToken, string JSONVALUE) //John added on 16-Feb-2022 For Version 4 OrderID changed to string (ChargeFOMOPAY )
        {
            string sAPIResponse = string.Empty;
            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransactionV4/Create?clientDb='" + dbname + "'");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BearerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }
        #endregion

        #region   WEBORDERTRANS API POST 


        /// <summary>
        ///  This API Call to Create Post Method Into WebOrder Tables 
        ///  The Purpose of this Method to Call the Order in Pos using Orderid 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string APICALL_WebOrde_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WeborderTransaction/Create?clientDb='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }

        #endregion  

        #region  CUSTOMER GUEST  RELEATED GET & POST MEHODS 

        /// <summary>
        ///  Get the maxid in Customers Guest using HQ Value 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarerToken"></param>
        /// <returns></returns>
        public string Api_Getmaxid_Guest(string dbname, string BarerToken)
        {

            string SApiResponese = string.Empty;


            var client = new RestClient("" + BaseUrl + "/api/'" + dbname + "'/CustomerGuest/GetMaxid_Guest");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        ///  This function to post data to CustomersGuest Table using Hq Value 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string CustomerGuest_Create(string dbname, string BarToken, string JSONVALUE)
        {


            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/CustomerGuest/Create?clientdb='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;



        }
        /// <summary>
        ///  Get CustLast id In Customer Guest Using Id's Value
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Api_GetCustLastID(string dbname, string BarerToken, string id)
        {


            string SApiResponese = string.Empty;


            var client = new RestClient("" + BaseUrl + "/api/'" + dbname + "'/CustomerGuest/GetCustLastValue/ID?ID=" + id + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            SApiResponese = response.Content;
            return SApiResponese;




        }

        /// <summary>
        ///  Get the ID using Cutomerid in HQ'S CustomerGuest 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="Customerid"></param>
        /// <returns></returns>
        public string Api_GetID(string BarerToken, string HQ, string Customerid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/CustomerGuest/GetID/customerid?customerid=" + Customerid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        #endregion

        #region  PMS RELEATED GET METHODS 

        /// <summary>
        ///  Get  the Cm_id from  PMS 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <returns></returns>
        public string Api_GetCm_id(string dbname, string BarerToken, string HQ)
        {


            string SApiResponese = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/" + dbname + "/PMS/GetCm_id/" + HQ + " ");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            SApiResponese = response.Content;
            return SApiResponese;
        }

        #endregion

        #region CUSTOMERS RELEATED GET & POS METHOS 

        /// <summary>
        ///  Check the MobileNo is exist or not using MobileNO In Customers table 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="MobileNo"></param>
        /// <returns></returns>
        public string Api_ChkMobileNo(string BarerToken, string HQ, string MobileNo)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetMobileNo/" + MobileNo + " ");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        public string Api_GetMobileNoValue(string BarerToken, string HQ, string MobileNo)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetMobileNoValue/" + MobileNo + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        /// <summary>
        ///  Get the Customerid using mobileno in Customers Table 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="MobileNo"></param>
        /// <returns></returns>
        public string Api_GetCusetomerid(string BarerToken, string HQ, string MobileNo)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetCustomerid/" + MobileNo + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        ///  Get MaxCustid in HQ'S  Customers Table 
        /// </summary>
        /// <param name="HQdbname"></param>
        /// <param name="BarerToken"></param>
        /// <returns></returns>
        public string Api_Getmaxid(string HQdbname, string BarerToken)
        {

            string SApiResponese = string.Empty;


            var client = new RestClient("" + BaseUrl + "/api/" + HQdbname + "/Customers/GetMaxCustID");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        /// POST :  Create Customers Using HQ's Values   
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string Customers_Create(string dbname, string BarToken, string JSONVALUE)
        {


            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/Customers/Create?clientdb='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;



        }
        /// <summary>
        ///  Get the CustomerID on Customers  Using MobileNO
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="MobileNo"></param>
        /// <returns></returns>
        public string Api_GetCustomersID(string BarerToken, string HQ, string MobileNo)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetCustomerid/" + MobileNo + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        /// <summary>
        ///  Get the Customer Info using the Customerid in HQ's Customers Table 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="Customerid"></param>
        /// <returns></returns>
        public string Api_GetCustomersDetail(string BarerToken, string HQ, string Customerid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetCustomerDetails/Customerid?Customerid=" + Customerid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        /// <summary>
        ///  Get MobileNo using Customerid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="Customerid"></param>
        /// <returns></returns>
        public string Api_GetMobileNO(string BarerToken, string HQ, string Customerid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ + "/Customers/GetMobileNo_Success/Customerid?Customerid=" + Customerid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        #endregion

        #region ORDERS RELEATED GET METHODS 
        /// <summary>
        ///  Get Orders Complete Transaction 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="BranchName"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public string Api_GetOrderComplete(string BarerToken, string HQ, string BranchName, string userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/Orders/GetOrders/" + HQ + "/" + userid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        ///  Get the Orders With Hold Transaction 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="HQ"></param>
        /// <param name="BranchName"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public string Api_GetOrderHold(string BarerToken, string HQ, string BranchName, string userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/Orders/GetOrdersHold/" + HQ + "/" + userid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        #endregion

        #region  MENU AND PRODUCTLIST , CATEGORY RELELATED  GET METHODS 

        /// <summary>
        ///  Get the CategoryDetails By Categoryid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public string Api_GetCategoryDetailByCategoryId(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderCategory/GetCategoryById/" + Categoryid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        ///  This Function Returns the ProductList by Categoryid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public string Api_ProductListByCategoryId(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderMenuList/GetWeborderProductByCategoryid/" + Categoryid + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        public string Api_ProductListByCategoryidVal(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderProducts/GetProducts/" + Categoryid + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        public string Api_ProductListByZeroClassByCategoryidVal(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderProducts/GetProductsWithZeroclass/" + Categoryid + "");


            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        public string Api_MenuList(string BarerToken, string BranchName)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderMenuList/GetWeborderMenu");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        #endregion

        #region  Inventory Releated GET Methods


        /// <summary>
        ///  This Method uses to Get the UnitCost using Barcode In Inventory 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Barcode"></param>
        /// <returns></returns>
        public string Api_GetUnitCost(string BarerToken, string BranchName, string Barcode)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/InventoryUnitcost/GetUnitcost/" + Barcode + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        public string API_GetInventoryOutStock(string sBarerToken, string DBName, string sBarcode) //JOHN ADDED ON 31-DEC-2020 GET NOT AVAILABLE VALUE
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DBName + "/InventoryOutofStock/GetInventoryOutStock/Barcode?Barcode=" + sBarcode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            var obj = JsonConvert.DeserializeObject(response.Content);
            dynamic result = JsonConvert.DeserializeObject<dynamic>(obj.ToString());
            var vOutofStock = result.OutofStock;
            sAPIResponse = vOutofStock;
            return sAPIResponse;
        }

        public string API_GETInventoryDetailByBarcode(string BearerToken, string DBName, string Barcode)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DBName + "/Inventory/GetInventoryDetails/Barcode?Barcode=" + Barcode + "");
            //var client = new RestClient("http://localhost:61760/api/da1/Inventory/GetInventoryDetails/Barcode?Barcode=" + Barcode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        public string API_GETGroupIDByGroupName(string BearerToken, string DBName, string GroupName)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DBName + "/DFDownload/GetGroup1IDbyGroupName/" + GroupName + "");
            //var client = new RestClient("http://localhost:61760/api/da1/DFDownload/GetGroup1IDbyGroupName/" + GroupName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }


        #endregion

        #region  WebTokenMaster Related GET Methods 


        //Need to consume it after API Update 
        public string Api_ChTableStatus(string BarerToken, string BranchName, string TableNo)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WebTokenMaster/ChkTableStatusValue/" + TableNo + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("text/plain", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }



        public string Api_GetWebTokenTableStatus(string BarerToken, string BranchName, string TableNo, string Token)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WebTokenMaster/GetTableStatus/" + TableNo + "/" + Token + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }




        public string Api_GetAddonItemId(string BarerToken, string BranchName, string Transid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WebTokenMaster/GetAddonItemid/" + Transid + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        #endregion

        #region  All PUT Methods  

        /// <summary>
        /// PUT Method  For Update Itemid and Transid   
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string Webtoken_UpdateItemidTransId(string dbname, string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/WebTokenMaster/UpdateItemidTransid");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();


            return sAPIResponse;

        }

        #endregion

        #region   ORDERS RELEATED  ALL GET METHODS


        /// <summary>
        ///  This Api Get method returns the OrderList of Complete Payment 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="HQ"></param>
        /// <param name="Userid"></param>
        /// <returns></returns>
        public string Api_GetOrderListCompletePayment(string BarerToken, string BranchName, string HQ, string Userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/Orders/GetOrders/" + HQ + "/" + Userid + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        /// <summary>
        ///  This Fuction Returns the Hold Transaction using Userid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="HQ"></param>
        /// <param name="Userid"></param>
        /// <returns></returns>
        public string Api_GetOrderListHoldTransaction(string BarerToken, string BranchName, string HQ, string Userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/Orders/GetOrdersHold/" + HQ + "/" + Userid + "");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);


            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }
        /// <summary>
        /// This Function Returns Between two Date Range using userid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="HQ"></param>
        /// <param name="Userid"></param>
        /// <param name="Startdt"></param>
        /// <param name="Enddt"></param>
        /// <returns></returns>
        public string Api_GetOrderListBetweenTwoDates(string BarerToken, string BranchName, string HQ, string Userid, string Startdt, string Enddt)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/Orders/GetOrderbyDataRange/" + HQ + "/" + Userid + "/" + Startdt + "/" + Enddt + " ");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        /// <summary>
        ///  This Function returns the Header Information of orders 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Userid"></param>
        /// <returns></returns>
        public string Api_GetOrdersHeader(string BarerToken, string BranchName, string Userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderOrderDetailChild/GetOrderDetailsChild/" + Userid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }


        /// <summary>
        ///  This Function Returns the OrderDetails Userid 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Userid"></param>
        /// <returns></returns>
        public string Api_GetOrdersDetails(string BarerToken, string BranchName, string Userid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderOrderDetailsHeader/GetOrderDetailsHeader/" + Userid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        //john added on 26-Jan-2022
        public string API_GetWebOrderCondimentGroup(string BearerToken, string DB, string CondimentGroupID)
        {
            string sAPIResponse = string.Empty;
            //var client = new RestClient("http://localhost:61760/api/" + DB + "/WeborderMenuList/GetWebOrderCondimentGroupbyCondimentGroupID/" + CondimentGroupID + "");
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderMenuList/GetWebOrderCondimentGroupbyCondimentGroupID/" + CondimentGroupID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        #endregion

        #region WEBTABLELIST API 

        public string API_POSTWebTableList(string sBarerToken, string DBName, int iWebTransID, int iWebItemID, string sWebTableNo, string sTransDate) // POST WEBTABLELIST JOHN ADDED ON 22-DEC-2020
        {
            string sAPIResponse = string.Empty;
            var lJSON = "{\"webTransID\": " + iWebTransID + "," +
                        "\"webItemID\": " + iWebItemID + ", " +
                        " \"webTableNo\":\"" + sWebTableNo + "\"," +
                        " \"webTableStatus\": 1," +
                        " \"webTransTime\":\" " + sTransDate + "\"}";

            var Client = new RestClient("" + BaseUrl + "/api/WebTableList/Create?clientDB='" + DBName + "' ");
            Client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", lJSON, ParameterType.RequestBody);
            var response = Client.Execute(request);

            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }

        public string API_PUTWebTableListItemID(string sBarerToken, string sDB, int iWebTransID, string sWebTableNo, int iWebItemID) // PUT WEBTABLELIST JOHN ADDED ON 22-DEC-2020
        {
            string sAPIResponse = string.Empty;
            var lJSON = "{\"webTransID\": " + iWebTransID + "," +
                        " \"webTableNo\":\"" + sWebTableNo + "\"," +
                         "\"webItemID\": " + iWebItemID + ", " +
                        " \"dbName\":\" " + sDB + "\"}";
            var Client = new RestClient("" + BaseUrl + "/api/WebTableList/UpdateWebTableListItemID");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", lJSON, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();

            return sAPIResponse;
        }

        public string API_GETWebTableListTransID(string sBarerToken, string sDB, string sWebTableNo) // GET WEBTABLELIST TRANSID JOHN ADDED ON 22-DEC-2020
        {
            string sAPIResponse = string.Empty;
            var Client = new RestClient("" + BaseUrl + "/api/" + sDB + "/WebTableList/GetTableListTransID/" + sWebTableNo + "");
            Client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", sBarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);

            IRestResponse response = Client.Execute(request);
            var obj = JsonConvert.DeserializeObject(response.Content);
            dynamic result = JsonConvert.DeserializeObject<dynamic>(obj.ToString());
            if (result == null)
            {
                sAPIResponse = "0";
            }
            else
            {
                var vWebTransID = result.WebTransID;
                sAPIResponse = vWebTransID;
            }
            return sAPIResponse;
        }

        public string API_GETWEbTableListItemID(string sBarerToken, string sDB, int iTransID) // GET WEBTABLELIST ITEMID JOHN ADDED ON 22-DEC-2020
        {

            string sAPIResponse = string.Empty;
            var Client = new RestClient("" + BaseUrl + "/api/" + sDB + "/WebTableList/GetTableListItemID/" + iTransID + "");
            Client.Timeout = -1;
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", sBarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);

            IRestResponse response = Client.Execute(request);
            var obj = JsonConvert.DeserializeObject(response.Content);
            dynamic result = JsonConvert.DeserializeObject<dynamic>(obj.ToString());

            if (result == null)
            {
                sAPIResponse = "0";
            }
            else
            {
                var vWebItemID = result.WebItemID;
                sAPIResponse = vWebItemID;
            }
            return sAPIResponse;
        }

        #endregion


        #region   WEBORDER NEW PRODUCTLIST WITH TIME CONSTRAINS  ( Added Karthik on 12-05-21 )  

        /// <summary>
        ///  This Put Call to Update the Outofstock column in inventory using categoryid 
        ///  Purpose : Weborder 
        /// </summary>
        /// <param name="sBarerToken"></param>
        /// <param name="sDB"></param>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public string API_PUT_WeborderOutofStock(string sBarerToken, string sDB)
        {
            string sAPIResponse = string.Empty;

            var Put_Json = "{\"dbName\":\" " + sDB + "\"}";


            var Client = new RestClient("" + BaseUrl + "/api/WeborderOutofStock/UpdateOutofstock");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", Put_Json, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }

        /// <summary>
        ///  This PUT Api Call Update the OutofStock column in Inventory Based on two Timing (Compare with   timeschedule) 
        /// </summary>
        /// <param name="sBarerToken"></param>
        /// <param name="sDB"></param>
        /// <param name="Categoryid"></param>
        /// <param name="Dayname"></param>
        /// <returns></returns>
        public string API_PUT_WeborderOutofStockByTiming(string sBarerToken, string sDB, string Dayname)
        {
            string sAPIResponse = string.Empty;

            var Put_Json = "{\"dbName\":\" " + sDB + "\"}";

            var Client = new RestClient("" + BaseUrl + "/api/WeborderOutofStock/UpdateOutofStockByTiming/" + Dayname + "");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", Put_Json, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        /// <summary>
        /// This Method for Next Day : 24 Hours 
        // Added on 12-01-23 [ Need to merge later to Deazure Main Code]
        /// </summary>
        /// <param name="sBarerToken"></param>
        /// <param name="sDB"></param>
        /// <param name="Dayname"></param>
        /// <returns></returns>
        public string API_PUT_WeborderOutofStockBy24HoursTiming(string sBarerToken, string sDB, string Dayname)
        {
            string sAPIResponse = string.Empty;

            var Put_Json = "{\"dbName\":\" " + sDB + "\"}";

            var Client = new RestClient("" + BaseUrl + "/api/WeborderOutofStock/UpdateOutofStockByTimingin24hours/" + Dayname + "");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", Put_Json, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }




        /// <summary>
        ///  This Get Call to get the Products List using Categoryid 
        ///  This Get Method to be invoke after the Outofstock column Update in Inventory 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public string API_GET_GetProducts(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderProducts/GetProducts/" + Categoryid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        /// <summary>
        /// This Get Call to get the Products List with Zero Class  using Categoryid 
        /// This Get Method to be invoke after the Outofstock column Update in Inventory 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="BranchName"></param>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public string API_GET_GetProductsWithZeroClass(string BarerToken, string BranchName, string Categoryid)
        {
            string SApiResponese = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/" + BranchName + "/WeborderProducts/GetProductsWithZeroclass/" + Categoryid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SApiResponese = response.Content;
            return SApiResponese;

        }

        #endregion

        #region NEW PRODUCT LAYOUT

        //john added on 22-Apr-2021
        public string Api_ModifierControlbyControlCode(string BarerToken, string DB, string ControlCode)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderModifierControl/GetModifierControlbyControlCode/" + ControlCode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;
        }

        public string Api_ModifierControlbyControlTypeandControlCode(string BearerToken, string DB, string ControlType, string ControlCode)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderModifierControl/GetModifierControlbyControlTypeandControlCode/" + ControlType + "/" + ControlCode + "");
            //var client = new RestClient("http://localhost:61760/api/da1/WebOrderModifierControl/GetModifierControlbyControlTypeandControlCode/" + ControlType + "/" + ControlCode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        public string Api_GetCondimentlistbyGroupName(string BarerToken, string DB, string Groupname)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderMenuList/GetWeborderCondimentbygroupname/" + Groupname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;


        }
        #endregion

        #region WEBORDER  TOP PICK RELATED  Added Karthik on 18-5-21

        public string API_POST_TopPick_Truncate(string sBarerToken, string DBName) // 
        {
            string sAPIResponse = string.Empty;
            var Client = new RestClient("" + BaseUrl + "/api/WebOrderTopPick/TruncateTopPick?clientdb=" + DBName + "");
            Client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");

            var response = Client.Execute(request);

            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }



        public string API_GET_Categoryids(string BarerToken, string DB)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/'" + DB + "'/DFDownload/GetInventoryCategories");

            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;


        }


        public string API_GET_Toppick3_in_WeborderTransDetail(string BarerToken, string DB, string categoryid)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/'" + DB + "'/WebOrderTopPick/GetTopPick_In_WeborderTransDetail/" + categoryid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;


        }
        public string API_GET_Toppick3_in_WebTransDetail(string BarerToken, string DB, string categoryid)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/'" + DB + "'/WebOrderTopPick/GetTopPick_In_WebTransDetail/" + categoryid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;


        }


        public string API_POST_TopPick(string sBarerToken, string DBName, string barcode, string categoryid)
        {
            int sid = 0;
            string sAPIResponse = string.Empty;
            var lJSON = "{\"id\": " + sid + "," +
                        "\"barcode\":\"" + barcode + "\"," +
                        "\"categoryid\": " + categoryid + "}";
            var Client = new RestClient("" + BaseUrl + "/api/WebOrderTopPick/Create?clientDb='" + DBName + "'");
            Client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", lJSON, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }



        public string API_PUT_TopPickupDataAllToZero(string sBarerToken, string sDB)
        {
            string sAPIResponse = string.Empty;

            var Client = new RestClient("" + BaseUrl + "/api/'" + sDB + "'/Webinventory/TopPickUpdate");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();

            return sAPIResponse;
        }


        public string API_PUT_ActiveTopPickupData(string sBarerToken, string sDB)
        {
            string sAPIResponse = string.Empty;

            var Client = new RestClient("" + BaseUrl + "/api/'" + sDB + "'/Webinventory/ActiveTopPickUpdate");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();

            return sAPIResponse;
        }



        #endregion

        #region WEB INI
        public string API_GET_INIWebOrderingIniValue(string sBarerToken, string sDB, string IniID)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/'" + sDB + "'/WebIniSetting/GetIniSettingbyIniID/" + IniID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }
        #endregion

        #region Promotion & QueueNo Related API'S

        //public string API_GETPromolist(string BarerToken, string DB)
        //{
        //    string sAPIResponse = string.Empty;
        //    var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderPromo/GetWebOrderPromo");
        //    client.Timeout = -1;
        //    var request = new RestRequest(Method.GET);
        //    request.AddHeader("Authorization", BarerToken);
        //    request.AddParameter("application/json", "", ParameterType.RequestBody);
        //    IRestResponse response = client.Execute(request);
        //    sAPIResponse = response.Content;
        //    return sAPIResponse;
        //}
        public string API_GETPromolist(string BarerToken, string DB)
        {
            string sAPIResponse = string.Empty;
            string JSONRetVal = API_GET_INIWebOrderingIniValue(BarerToken, DB, "7"); // PROMO ORDER BY
            var sObject = "[" + JsonConvert.DeserializeObject(JSONRetVal).ToString().Trim() + "]";
            DataTable dtResult = (DataTable)JsonConvert.DeserializeObject(sObject, (typeof(DataTable)));
            string PromoOrderby = (dtResult.Rows[0]["ini_value"]).ToString();

            if (PromoOrderby.ToString() == "0") //john added on 18-Aug-2021 - 0=Follow Default Order by
            {
                var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderPromo/GetWebOrderPromo");
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", BarerToken);
                request.AddParameter("application/json", "", ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                sAPIResponse = response.Content;
                // return sAPIResponse;
            }
            else if (PromoOrderby == "1") // 1 = Follow Main and Sub Orber by
            {
                var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderPromo/WeborderPromoPostionbyMainandSub");
                //var client = new RestClient("http://localhost:61760/api/da1/WeborderPromo/WeborderPromoPostionbyMainandSub");
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", BarerToken);
                request.AddParameter("application/json", "", ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                sAPIResponse = response.Content;
                //return sAPIResponse;
            }
            return sAPIResponse;

        }

        public string APIPromoShowItemCount(string sBarerToken, string DB) //John Added on 27-July-2021
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/PromotionLimit/GetPromoLimit");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        public string API_GETWebOrderQueueRunID(string sBarerToken, string DB, string BusinessDate)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderQueue/GetOrderQueue_RunID/" + BusinessDate + "");
            //var client = new RestClient("http://localhost:61760/api/da1/WebOrderQueue/GetOrderQueue_RunID/" + BusinessDate + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        public string API_GETWebOrderQueueContinuousRunID(string sBarerToken, string DB)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderQueue/GetOrderQueue_ContinuousRunID");
            //var client = new RestClient("http://localhost:61760/api/da1/WebOrderQueue/GetOrderQueue_ContinuousRunID");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }

        public string API_PUTWebOrderQueueRunID(string sBarerToken, string DB, string JSON)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/WebOrderQueue/UpdateWebOrderQueueRunID");
            //var client = new RestClient("http://localhost:61760/api/WebOrderQueue/UpdateWebOrderQueueRunID");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSON, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }

        public string API_PUTWebOrderQueueRunIDContinuous(string sBarerToken, string DB, string JSON)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/WebOrderQueue/UpdateWebOrderQueueContinuousRunID");
            //var client = new RestClient("http://localhost:61760/api/WebOrderQueue/UpdateWebOrderQueueContinuousRunID");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSON, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }

        public string API_POSTWebOrderQueue(string sBarerToken, string DB, string JSON)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/WebOrderQueue/Create?ClientDB=" + DB);
            //var client = new RestSharp.RestClient("http://localhost:61760/api/WebOrderQueue/Create?ClientDB='" + DB + "'");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content_Type", "application/json");
            request.AddParameter("application/json", JSON, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }

        public string API_GETWebPriceCaption(string sBearerToken, string DB, int WebPriceCaptionPriceID, int PriceID) //john added on 16-Nov-2021
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebPriceCaptionDetail/GetPriceCaptionbyTransIDandPriceType/" + WebPriceCaptionPriceID + "/" + PriceID + "");
            //var client = new RestClient("http://localhost:61760/api/" + DB + "/WebPriceCaptionDetail/GetPriceCaptionbyTransIDandPriceType/" + WebPriceCaptionPriceID + "/" + PriceID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", sBearerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }
        #endregion

        #region   WEBORDER ONLINE TRANSACTIONN API POST   [ Karthik : Added  16-11-2021 ]
        /// <summary>
        ///  Weborder OnlineTransaction ( Its Inserts : onlinetrans , onlinetransdetail , onlinetransdetailcondiment ) 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string APICALL_OnlineTransaction_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WeborderOnlineTransaction/Create?clentdb='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        /// <summary>
        ///  This Method For Online TransPayment 
        ///  This is Require for Online Transaction
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string APICALL_OnlineTransPayment_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebOrderOnlineTranspayment/Create?ClientDB='" + dbname + "' ");
            client.Timeout = -1;


            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        public string APICALL_OnlineTrandetail_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebOrderOnlineTransdetail/Create?ClientDB='" + dbname + "' ");
            client.Timeout = -1;


            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }

        public string APICALL_OnlineTrandetailCondiment_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WeborderOnlineTransdetailCondiment/Create?ClientDB='" + dbname + "' ");
            client.Timeout = -1;


            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        /// <summary>
        ///  This Function Uses to Update the Onlinetrans on Addon  Table Using Transid 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string APICALL_UpdateOnlineTranslOnAddOn(string dbname, string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/WeborderOnlinetrans/UpdateOnlineTransAddon");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();


            return sAPIResponse;

        }

        public string API_GetPriceFlag(string BearerToken, string DB, string Barcode)
        {
            string sAPIResponse = string.Empty;
            //var client = new RestClient("http://54.251.229.140:4545/api/" + DB + "/WeborderPriceFlag/GetWeborderPriceFlagByBarcode/" + Barcode + "");
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderPriceFlag/GetWeborderPriceFlagByBarcode/" + Barcode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }



        #region  WebOrerId Reset To '0'  Karthik Added On 10-01-22

        /// <summary>
        ///  This  Get Method To GetMaxid in WeborderMaster Table 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        public string API_GetMaxidofWebOrderId(string BarerToken, string DB)
        {
            string SAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderIdMaster/GetMaxidOnWebOrderId");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            SAPIResponse = response.Content;
            return SAPIResponse;


        }

        /// <summary>
        ///  This Function Update the  Max WebOrderId in WebOrderIdTable 
        /// </summary>
        /// <param name="sBarerToken"></param>
        /// <param name="sDB"></param>
        /// <param name="WebOrderId"></param>
        /// <returns></returns>
        public string API_PUT_WeborderIdUpdate(string sBarerToken, string sDB, string WebOrderId)
        {
            string sAPIResponse = string.Empty;
            var Put_Json = "{" +
                               "\"weborderId\":\"" + WebOrderId + "\"," +
                               "\"dbName\":\"" + sDB + "\"" +
                            "}";

            var Client = new RestClient("" + BaseUrl + "/api/WebOrderIdMaster/UpdateWeborderIdOnLastId");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", Put_Json, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        /// <summary>
        ///  This Function To Reset the WebOrderId In WebOrderIdMaster Table 
        /// </summary>
        /// <param name="sBarerToken"></param>
        /// <param name="sDB"></param>
        /// <param name="ResetDate"></param>
        /// <returns></returns>
        public string API_PUT_WeborderIdReset(string sBarerToken, string sDB, string ResetDate)
        {
            string sAPIResponse = string.Empty;


            var Put_Json = "{" +
                               "\"resetDate\":\"" + ResetDate + "\"," +
                               "\"dbName\":\"" + sDB + "\"" +
                            "}";

            var Client = new RestClient("" + BaseUrl + "/api/WebOrderIdMaster/UpdateWeborderIdForReset");
            Client.Timeout = -1;
            var request = new RestRequest(Method.PUT);

            request.AddHeader("Authorization", sBarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", Put_Json, ParameterType.RequestBody);
            var response = Client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }

        #endregion



        #endregion

        #region Payment Gateway APIs
        /// <summary>
        ///  This API Call to Create Post Method Into PayFomo Table
        ///  The Purpose of this Method to Register a subsequent record on PayFomo table once FomoPAY created an order
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string APICALL_PayFomo_Create(string dbname, string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;

            //var client = new RestSharp.RestClient("" + BaseUrl + "/api/WeborderTransaction/Create?clientDb='" + dbname + "' ");
            var client = new RestClient("" + BaseUrl + "/api/PayFomo/Create?clientDb= " + dbname + " ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }

        #endregion

        #region TransactionTMP API's John added on 23-Apr-2022
        public string APICALL_Create_TransactionTMP(string dbName, string BarToken, string JSONVALUE)
        {
            //dbName = "da2";
            string sAPIResponse = string.Empty;
            //var client = new RestSharp.RestClient("http://localhost:61760/api/WebTransactionTmpV5/Create?clientDB='" + dbName + "'");
            var client = new RestSharp.RestClient("" + BaseUrl + "/api/WebTransactionTmpV5/Create?clientdb='" + dbName + "' ");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }

        public string APICALL_GET_TransTmpLastTransNo(string BarToken, string dbName)
        {
            string sAPIResponse = string.Empty;
            var Client = new RestClient("" + BaseUrl + "/api/'" + dbName + "'/WebTransV5/GetTransTmpLastTransNoV5");
            //var Client = new RestClient("http://localhost:61760/api/" + dbName + "/WebTransV5/GetTransTmpLastTransNoV5");
            Client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = Client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }
        #endregion

        #region PROMOCODE 

        /// <summary>
        ///  Get the PromoCode Details using the Promocode 
        /// </summary>
        /// <param name="BarerToken"></param>
        /// <param name="DB"></param>
        /// <param name="_promocode"></param>
        /// <returns></returns>
        public string API_GET_PromoCodeDetails(string BarerToken, string DB, string _promocode)
        {
            string sAPIResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebOrderPromoCode/GetPromoCodeDetails/" + _promocode + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BarerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.Content;
            return sAPIResponse;
        }



        #endregion

        #region  TransPaymenttmpm POST : When  0 Total Condition  
        // This Post Normally happens in WebHook Application , This Post invoked when Total is 0
        // Karthik  Added on 30-06-22 
        public string APICALL_TranPaymentTmp_Create(string dbname, string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestSharp.RestClient("" + BaseUrl + "/api/TransPaymentTMP/Create?clientDB='" + dbname + "' ");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request);


            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;



        }


        #endregion 

        #region MenuData
        public string API_GETMenuData(string BearerToken, string DB)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WebMenuOrder/GetMenuOrder");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }
        #endregion

        #region  Get the WeborderTax   Controller : WeborderTax
        public string API_GET_WebOrderTax(string BearerToken, string DB, string Taxid)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderTax/GetWeborderTax/" + Taxid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }

        #endregion

        #region  Get the Operative Hours    Controller : WeborderOperativeHours
        public string API_GET_WebOrderOperativeHours(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderOperativeHours/GetOperativeHoursByDay/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }





        public string API_GET_WebOrderOperativTiming(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderOperativeHours/GetOperativeTiming/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }



        #endregion

        #region iCRM Module

        // nid added Get the Customer Informations using MobileNo 
        public string iCRM_GetCustomersDetails(string dbname, string BarerToken, string mobileno)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/ICRMCustomers/" + dbname + "/GetCustomerDetails/Mobile?Mobile=" + mobileno + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;


            return SApiResponese;


        }

        // Post the Customer Information using MobileNo 
        public string iCRM_CustomersCreate(string dbname, string BarToken, string JSONVALUE)
        {

            string sApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api" + "/ICRMCustomers/Create?clientDB=" + dbname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;
            return sApiResponese;
        }

        // Post the Cashback Transaction  
        public string iCRM_CashbackTransactionCreate(string dbname, string BarToken, string JSONVALUE)
        {

            string sApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api" + "/ICRMCashbackTrans/Create?clientDB=" + dbname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer" + " " + BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;
            return sApiResponese;
        }

        // Get the CashbackBalance using MobileNo 
        public string iCRM_CashbackBalance(string dbname, string BarerToken, string mobileno)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/ICRMCashbackTrans/" + dbname + "/GetCashbackBalance/Mobile?Mobile=" + mobileno + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;


            return SApiResponese;


        }

        // Get the CashBack Balance By CID 
        public string iCRM_CashbackBalance_By_CID(string dbname, string BarerToken, string CID)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/ICRMCashbackTrans/" + dbname + "/GetCashbackBalanceByCID/CID?CID=" + CID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;


            return SApiResponese;


        }







        // Post the CustomersPIN using CID 
        public string iCRM_CustomersCreatePIN(string dbname, string BarToken, string JSONVALUE)
        {

            string sApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api" + "/ICRMCustomersPIN/Create?clientDB=" + dbname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;
            return sApiResponese;
        }


        // Get the CustomersPIN using CID 
        public string iCRM_GetCustomersPIN(string dbname, string BarerToken, string cid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/ICRMCustomersPIN/" + dbname + "/GetCustomersPIN/CID?CID=" + cid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;
            return SApiResponese;
        }

        // Reset iCRM Customers PIN using CID
        public string iCRM_ResetCustomersPIN(string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/ICRMCustomersPIN/UpdateCustomersPIN");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;
        }



        /// <summary>
        /// Get the Membershipdetails using membershipid 
        /// </summary>
        /// <param name="HQ_dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="Membershipid"></param>
        /// <returns></returns>
        public string iCRM_GetMembershipByMembershipId(string HQ_dbname, string BarerToken, string Membershipid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ_dbname + "/IMembership/GetMembershipDetails/" + Membershipid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;
            return SApiResponese;
        }
        /// <summary>
        /// Get the LoyaltyPointsDetails By LPID
        /// </summary>
        /// <param name="HQ_dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="LpId"></param>
        /// <returns></returns>
        public string iCRM_Get_LoyaltyPointsDetailsByLPID(string HQ_dbname, string BarerToken, string LpId)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ_dbname + "/ILoyaltyPoints/Getloyaltypoint/" + LpId + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;
            return SApiResponese;
        }


        public string iCRM_GetAllCustomer(string db, string bearertoken)
        {
            var client = new RestClient("" + BaseUrl + "/api/ICRMCustomers/" + db + "/GetAllCustomers");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            IRestResponse response = client.Execute(request);
            return response.Content;
        }



        /// <summary>
        /// Get the current Points By CID 
        /// </summary>
        /// <param name="HQ_dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="Cid"></param>
        /// <returns></returns>
        public string iCRM_Get_CurrentPointByCID(string HQ_dbname, string BarerToken, string Cid)
        {
            string SApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + HQ_dbname + "/ILoyaltyPointsDetail/GetCurrentPoints/" + Cid + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            SApiResponese = response.Content;
            return SApiResponese;
        }
        /// <summary>
        /// Create the LoyaltyPointsDetails 
        /// </summary>
        /// <param name="dbname"></param>
        /// <param name="BarerToken"></param>
        /// <param name="JSONVALUE"></param>
        /// <returns></returns>
        public string iCRM_ILoyaltyPointsDetail_Create(string dbname, string BarerToken, string JSONVALUE)
        {

            string sApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api" + "/ILoyaltyPointsDetail/Create?clientDB=" + dbname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;
            return sApiResponese;
        }




        public string Get_AESKey(string DB) //Karthik  added for Encryption key on 12-Sep-2024 
        {
            string sAESKey = string.Empty;
            string jsonaeskey = string.Empty;
            string BearerToken = string.Empty;
            string IniID = string.Empty;

            BearerToken = GetBarerToken();
            IniID = "68";
            jsonaeskey = API_GET_INIWebOrderingIniValue(BearerToken, DB, IniID);
            var objAESKey = "[" + JsonConvert.DeserializeObject(jsonaeskey).ToString() + "]";
            DataTable DTaeskey = (DataTable)JsonConvert.DeserializeObject(objAESKey, (typeof(DataTable)));
            sAESKey = DTaeskey.Rows[0]["ini_value"].ToString();
            return sAESKey;
        }



        #endregion 

        #region   Special Operative Hours

        // This Change Need to be Update the current API ( Sunuat Updated )

        public string API_GET_WebOrderSpecialOperativeHours(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderSpecialOperativeHours/GetOperativeHours_Time_Values/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }

        public string API_GET_WebOrderSpecialOperativeHours_Condition1(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderSpecialOperativeHours/GetSpecialhours_Condition1/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }

        public string API_GET_WebOrderSpecialOperativeHours_Condition2(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderSpecialOperativeHours/GetSpecialhours_Condition2/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }

        public string API_GET_WebOrderSpecialOperativeHours_24Hours(string BearerToken, string DB, string DayaName)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/WeborderSpecialOperativeHours/GetSpecialhours_24Hours/" + DayaName + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }



        public string PUT_WeborderOperative_UpdateTimes(string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/WeborderSpecialOperativeHours/UpdateTimeValue");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();


            return sAPIResponse;

        }


        #endregion

        #region Navision Integration

        #region Get Navision AccessToken
        public string Nav_GetBarerTokenAsync()
        {
            try
            {

                System.Net.ServicePointManager.Expect100Continue = false;
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                var options = new RestClientOptions("https://login.microsoftonline.com")
                {
                    MaxTimeout = -1,
                };
                var client = new RestClient("https://login.microsoftonline.com/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/oauth2/v2.0/token");
                var request = new RestRequest(Method.POST);
                request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                request.AddHeader("Cookie", "fpc=Aonu91_pSSxKvnK-mPi21wQdc8BQAQAAAE0Lt9wOAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd");
                request.AddParameter("grant_type", "client_credentials");
                request.AddParameter("client_id", "ba79ef23-75f1-4da7-9b96-a176763930b2");
                request.AddParameter("client_secret", "nVB8Q~y4eawwYRWMZlNIWkDhDqD-heWGIcvioaGt");
                request.AddParameter("scope", "https://api.businesscentral.dynamics.com/.default");
                RestResponse response = (RestResponse)client.Execute(request);
                Console.WriteLine(response.Content);


                // Reading Json Data : 
                var ReadData = JObject.Parse(response.Content.ToString());
                JArray ReadArray = new JArray();
                ReadArray.Add(ReadData);
                foreach (JToken ReadItem in ReadArray)
                {
                    BarerToken = ReadItem["access_token"].ToString();
                }

                return BarerToken;
            }
            catch (Exception e)
            {
                return null;
            }
        }

        #endregion

        #region Navision Get Brand Call
        public string Nav_GET_Brand(string BarerToken)
        {
            var options = new RestClientOptions("https://api.businesscentral.dynamics.com")
            {
                MaxTimeout = -1,
            };
            var client = new RestClient("https://api.businesscentral.dynamics.com");
            //var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Sandbox/api/afon/aud/v1.0/companies(f0fe3fa3-963d-ee11-bdf5-000d3acb1fd6)/posBrands", Method.GET );
            //var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Production/api/afon/aud/v1.0/companies(696472d8-bf68-ee11-8def-00224898c141)/posBrands", Method.GET);   //AUD
            var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Production/api/afon/aud/v1.0/companies(3865558b-f268-ee11-8def-00224898c141)/posBrands", Method.GET);     //CE
            request.AddHeader("Authorization", "Bearer " + BarerToken);
            var body = @"";
            request.AddParameter("text/plain", body, ParameterType.RequestBody);
            RestResponse response = (RestResponse)client.Execute(request);
            //Console.WriteLine(response.Content);
            return response.Content;
        }
        #endregion

        #region Navision Get Item Call
        public string Nav_GET_Item(string BarerToken)
        {
            var options = new RestClientOptions("https://api.businesscentral.dynamics.com")
            {
                MaxTimeout = -1,
            };
            var client = new RestClient("https://api.businesscentral.dynamics.com");
            //var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Sandbox/api/afon/aud/v1.0/companies(f0fe3fa3-963d-ee11-bdf5-000d3acb1fd6)/posItems", Method.GET);
            //var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Production/api/afon/aud/v1.0/companies(696472d8-bf68-ee11-8def-00224898c141)/posItems", Method.GET);    //AUD
            var request = new RestRequest("/v2.0/d82dbaf5-2a21-41d6-840e-4a1be4b839f5/Production/api/afon/aud/v1.0/companies(3865558b-f268-ee11-8def-00224898c141)/posItems", Method.GET);      //CE
            request.AddHeader("Authorization", "Bearer " + BarerToken);
            var body = @"";
            request.AddParameter("text/plain", body, ParameterType.RequestBody);
            RestResponse response = (RestResponse)client.Execute(request);
            //Console.WriteLine(response.Content);
            return response.Content;
        }


        #endregion

        #endregion

        #region XERO Integration  

        //For getting AccessToken using refresh token
        public string Xero_GetAccessToken(string refreshToken, string sXeroTokenURL, string sXeroAPIKey, string sXeroSecret)
        {
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(sXeroAPIKey + ":" + sXeroSecret);
            //Console.WriteLine(System.Convert.ToBase64String(plainTextBytes));
            string sXeroFinalAPIKey = System.Convert.ToBase64String(plainTextBytes);

            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sXeroTokenURL);
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Basic " + sXeroFinalAPIKey);
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Accept-Language", "en_US");
            request.AddHeader("client_id", sXeroAPIKey);
            //request.AddHeader("Cookie", "_abck=A64BD7FBB9575006E754415C21BD81E7~-1~YAAQj690y8XiM6mNAQAA2bogwAsb6lYhK/Uwm9hOZHzQHU3//AJuSFACqBEu1DVMHd01BO6sEjJUnf+rnuFZLdaVxAKJym78vVdnY5nRqbwVIij/QVAwlgmNT2N7Z5TGWitSRHaDUvdPSGiOK3I8if9PD9CT2TjgjutWVscVBAsKWrNSAm/umN9xB01oyTqths8datrQqTT918Bj9c92eOWZGtZJGyS7+Od3nF3A1R53oGHVPutrJwX/SD3aLjyW/VX7X280cRyf6NEqCnteNWqvco91uJu1kSDnYeVwEwDGjn9CX6tUGXETh4+UhleCoNcE2ZOxk9sgmgWTVbFtPpmS/mFTg65IQSa8gFDVJfgXQq3cZzd6cfEdhKUKG8WDqwqeq30=~-1~-1~-1; ak_bmsc=A3FC6641FBD6030893BEDDF3FB9EBD6F~000000000000000000000000000000~YAAQ1t6bfHlVaKONAQAA2oGPwBZ8GgDdlGB/y649kwYWRzPpPFopFGoyNIyfL0pPcscD82jScbgG4FOKU/bffwvTRitL0RAMUwAPPP1Ho0Aj4GiXPVbqxYqWQcIo+g3g2NZhG7MgaT+Z9AbTCbf9N9y6ux5cOU93HGUwW1cKGltIHHbbW/1uiqE/C0NmkcVbe/ZM3WPpw+LiBRUJZcsz5w9ufKqRVGcdTufNtUY3z/cxlss0uo3UMSqih3NxQYreF910dFDrtBDuUfEJpbC3ReHyovjM2qIHsBVO9/BY/f39cUVkwsF1vgFXxL+MsJHZcHLq2Mq5kfd4HBBJq6TWePIRoNhv/IQRCbNrwpqUPNFtRpRjuM5NhJhEDlJBJ8fJ+IDGVyFh; bm_sv=E36534CC86FDE848755A401021831836~YAAQ1t6bfCpRaaONAQAAlh+1wBbF5yFggDBb0O+RXF74IAPKcCTNym66gC6OLJRoGWORiMBgghMRulE6OCsC+2d8PGvYZMqnMcPR3Zi/VgtAqdW/NAkhuKf9/IDmny7on8qgHW3LiK9HewXkgqMkYp0TPRfvcFebjWTZpgg58drzy2xKeXg8EXkbuSqVtACqe1dKkAgZi1Zex/vLCnrFOIdcaHW6MZXGdf82mHB9gML5Vh2ceYjYZOBZAeLaAA==~1; bm_sz=6CD084CB8243372F4183895081DE4224~YAAQj690y8fiM6mNAQAA2bogwBZ8dvr6Qi42AR1uDzLShjdwqnQivii7a0ovkkXcVwN4Cj4th7pUSaqwVCqgHl2HkhCmBSBtlcBlYy6Zbm0/StsKT99Z4Chn/KpT3g71gGfbCso8CQDHHSQvjqL5HRBHcmGa0HyAMI6csozSllHL9uEiDJGqz5NrFzV5zROeZhXTinaiOu4ZnIct2M2xv+rn0aCYaFXI7kYWFM8Ykm8qQJOql9rPiVZeJMRESQIvOJDyTOewUFz54FfaPIkjolWEGLL+XkQyl6gVIPwGgcBZNMisyPkA4GvEJUkz8EcRHIYaUzrkkjf/ezC0~3683654~4536369; Device=282fa1770c644b3bb2378fc1745bc339");
            request.AddParameter("grant_type", "refresh_token");
            request.AddParameter("refresh_token", refreshToken);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);

            return response.Content;
        }

        // Post Sales summary to Xero
        public string Xero_CreateInvoice(string BarToken, string JSONVALUE, string XeroTenantID, string sXeroURL)
        {
            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sXeroURL + "/Invoices");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json;");
            request.AddHeader("Accept-Language", "en_US");
            request.AddHeader("xero-tenant-id", XeroTenantID);
            request.AddHeader("Authorization", "Bearer " + BarToken);
            //request.AddHeader("Cookie", "_abck=A64BD7FBB9575006E754415C21BD81E7~-1~YAAQj690y8XiM6mNAQAA2bogwAsb6lYhK/Uwm9hOZHzQHU3//AJuSFACqBEu1DVMHd01BO6sEjJUnf+rnuFZLdaVxAKJym78vVdnY5nRqbwVIij/QVAwlgmNT2N7Z5TGWitSRHaDUvdPSGiOK3I8if9PD9CT2TjgjutWVscVBAsKWrNSAm/umN9xB01oyTqths8datrQqTT918Bj9c92eOWZGtZJGyS7+Od3nF3A1R53oGHVPutrJwX/SD3aLjyW/VX7X280cRyf6NEqCnteNWqvco91uJu1kSDnYeVwEwDGjn9CX6tUGXETh4+UhleCoNcE2ZOxk9sgmgWTVbFtPpmS/mFTg65IQSa8gFDVJfgXQq3cZzd6cfEdhKUKG8WDqwqeq30=~-1~-1~-1");
            var body = JSONVALUE;
            request.AddParameter("application/json; charset=UTF-8", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;

            return sApiResponese;
        }


        // Post Payment summary to Xero
        public string Xero_UpdatePaymentDetails(string BarToken, string JSONVALUE, string XeroTenantID, string sXeroURL)
        {
            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sXeroURL + "/Payments");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json;");
            request.AddHeader("Accept-Language", "en_US");
            request.AddHeader("xero-tenant-id", XeroTenantID);
            request.AddHeader("Authorization", "Bearer " + BarToken);
            //request.AddHeader("Cookie", "_abck=A64BD7FBB9575006E754415C21BD81E7~-1~YAAQj690y8XiM6mNAQAA2bogwAsb6lYhK/Uwm9hOZHzQHU3//AJuSFACqBEu1DVMHd01BO6sEjJUnf+rnuFZLdaVxAKJym78vVdnY5nRqbwVIij/QVAwlgmNT2N7Z5TGWitSRHaDUvdPSGiOK3I8if9PD9CT2TjgjutWVscVBAsKWrNSAm/umN9xB01oyTqths8datrQqTT918Bj9c92eOWZGtZJGyS7+Od3nF3A1R53oGHVPutrJwX/SD3aLjyW/VX7X280cRyf6NEqCnteNWqvco91uJu1kSDnYeVwEwDGjn9CX6tUGXETh4+UhleCoNcE2ZOxk9sgmgWTVbFtPpmS/mFTg65IQSa8gFDVJfgXQq3cZzd6cfEdhKUKG8WDqwqeq30=~-1~-1~-1");
            var body = JSONVALUE;
            request.AddParameter("application/json; charset=UTF-8", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;

            return sApiResponese;
        }






        #endregion

        #region  iCurrentPoint   karthik added on 28-09-24 
        public string API_GET_ICurrentPoints(string BearerToken, string DB, string CID)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/ICurrentPoints/GetICurrentPoint/" + CID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }


        public string UpdateCurrentPointValue(string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/ICurrentPoints/UpdateCurrentPoints");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();


            return sAPIResponse;

        }

        public string UpdateCurrentPointValueWithPointExpiryMonths(string BarToken, string JSONVALUE)
        {
            string sAPIResponse = string.Empty;

            var client = new RestClient("" + BaseUrl + "/api/ICurrentPoints/UpdateCurrentPointsAndPointExpiry");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();


            return sAPIResponse;

        }






        // Added karthik On 28-09-24 
        // Post the CurrentPoint New Row In CurrentPoint Table by cid 
        public string iCRM_CurrentPoint_Create(string dbname, string BarerToken, string JSONVALUE)
        {

            string sApiResponese = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api" + "/ICurrentPoints/Create?ClientDB=" + dbname + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer" + " " + BarerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;
            return sApiResponese;
        }


        public string API_GET_PEMonths_By_Peid(string BearerToken, string DB, Int32 PEID)
        {
            string sResponse = string.Empty;
            var client = new RestClient("" + BaseUrl + "/api/" + DB + "/iPointExpiryMonths/GetIPointExpiryMonthsByPeid/" + PEID + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", BearerToken);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sResponse = response.Content;
            return sResponse;
        }

        


        #endregion

        #region ZOHO Integration
        //For getting AccessToken using refresh token
        public string Zoho_GetAccessToken(string refreshToken, string sZohoTokenURL, string sZohoAPIKey, string sZohoSecret)
        {

            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sZohoTokenURL + "/oauth/v2/token?refresh_token=" + refreshToken + "&client_id=" + sZohoAPIKey + "&client_secret=" + sZohoSecret + "&redirect_uri=http://localhost:5000/callback&grant_type=refresh_token");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddParameter("application/json", "", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            return response.Content;
        }

        // Post Sales summary to Zoho
        public string Zoho_CreateInvoice(string AccessToken, string sZohoURL, string JSONVALUE, string sOrganizationID)
        {
            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sZohoURL + "/invoice/v3/invoices");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json;");
            request.AddHeader("Accept-Language", "en_US");
            request.AddHeader("Authorization", "Zoho-oauthtoken " + AccessToken);
            request.AddHeader("X-com-zoho-invoice-organizationid", sOrganizationID);
            //request.Headers.Add("Cookie", "BuildCookie_858959405=1; JSESSIONID=067C8EFBB4E322E91C3EC34DAF79FBF7; _zcsr_tmp=e760fa21-f70a-48dc-9a88-7a296b4a7f5c; zalb_0d082fb755=5a6b80ee95ac0749616f0118188e9f66; zbcscook=e760fa21-f70a-48dc-9a88-7a296b4a7f5c");
            var body = JSONVALUE;
            request.AddParameter("application/json; charset=UTF-8", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;

            return sApiResponese;

        }

        // Post Payment summary to Zoho
        public string Zoho_CreatePayment(string AccessToken, string sZohoURL, string JSONVALUE, string sOrganizationID)
        {
            string sApiResponese = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var client = new RestClient(sZohoURL + "/invoice/v3/customerpayments");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json;");
            request.AddHeader("Accept-Language", "en_US");
            request.AddHeader("Authorization", "Zoho-oauthtoken " + AccessToken);
            request.AddHeader("X-com-zoho-invoice-organizationid", sOrganizationID);
            //request.Headers.Add("Cookie", "BuildCookie_858959405=1; JSESSIONID=067C8EFBB4E322E91C3EC34DAF79FBF7; _zcsr_tmp=e760fa21-f70a-48dc-9a88-7a296b4a7f5c; zalb_0d082fb755=5a6b80ee95ac0749616f0118188e9f66; zbcscook=e760fa21-f70a-48dc-9a88-7a296b4a7f5c");
            var body = JSONVALUE;
            request.AddParameter("application/json; charset=UTF-8", body, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            sApiResponese = response.Content;

            return sApiResponese;

        }

        #endregion

        #region Quickbook Integration

        //For getting AccessToken using refresh token
        public string Quickbook_GetAccessToken(string refreshToken, string sQBTokenURL, string sQBClientId, string sQBClientSecret)
        {
            string sApiResponse = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            try
            {
                // Encode clientId:clientSecret in Base64
                string authHeader = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(sQBClientId + ":" + sQBClientSecret));

                //var client = new RestClient(sQBTokenURL + "/oauth2/v1/tokens/bearer");
                var client = new RestClient(sQBTokenURL);
                client.Timeout = -1;

                var request = new RestRequest(Method.POST);
                request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                request.AddHeader("Accept", "application/json");
                request.AddHeader("Authorization", "Basic " + authHeader);

                // Add refresh token grant type
                request.AddParameter("grant_type", "refresh_token");
                request.AddParameter("refresh_token", refreshToken);

                IRestResponse response = client.Execute(request);

                if (response.IsSuccessful)
                {
                    sApiResponse = response.Content;
                }
                else
                {
                    //sApiResponse = $"Error: {response.StatusCode} - {response.Content}";
                }

                Console.WriteLine(sApiResponse);
            }
            catch (Exception ex)
            {
                sApiResponse = "Exception: " + ex.Message;
                Console.WriteLine(sApiResponse);
            }

            return sApiResponse;
        }

        //for getting payment types from quickbook
        public string Quickbook_GetPaymenttypes(string accessToken, string companyId, string sQBBaseURL)
        {
            string apiResponse = string.Empty;

            // TLS 1.2
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            // Build endpoint
            string url = sQBBaseURL + "/v3/company/" + companyId + "/query?minorversion=70";

            var client = new RestClient(url);
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/text");   // <-- Must be application/text
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", "Bearer " + accessToken);

            // Query in plain text
            request.AddParameter("application/text", "select * from PaymentMethod", ParameterType.RequestBody);

            // Execute
            IRestResponse response = client.Execute(request);

            apiResponse = response.Content;
            return apiResponse;
        }

        // For getting items from QuickBooks
        public string Quickbook_GetItems(string accessToken, string companyId, string sQBBaseURL)
        {
            string apiResponse = string.Empty;

            // TLS 1.2
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            // Build endpoint
            string url = sQBBaseURL + "/v3/company/" + companyId + "/query?minorversion=70";

            var client = new RestClient(url);
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/text");   // <-- Must be application/text
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", "Bearer " + accessToken);

            // Query for items
            // Note: Sku does not always return in field-limited queries, safest is SELECT *
            request.AddParameter("application/text", "select * from Item", ParameterType.RequestBody);

            // Execute
            IRestResponse response = client.Execute(request);

            apiResponse = response.Content;
            return apiResponse;
        }

        //For creating Quickbook invoice
        public string Quickbook_CreateInvoice(string accessToken, string companyId, string jsonPayload, string sQBtransURL)
        {
            string apiResponse = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            // QBO API URL
            string sQuickBooksURL = sQBtransURL + "/v3/company/" + companyId + "/invoice";

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

            // Headers
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", "Bearer " + accessToken);

            // Body
            request.AddParameter("application/json; charset=UTF-8", jsonPayload, ParameterType.RequestBody);

            // Execute
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            apiResponse = response.Content;

            return apiResponse;
        }

        //for CreatePayment call
        public string Quickbook_CreatePayment(string accessToken, string companyId, string jsonPayload, string sQBtransURL)
        {
            string apiResponse = string.Empty;
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            // QBO Payment API URL
            string sQuickBooksURL = sQBtransURL + "/v3/company/" + companyId + "/payment";

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

            // Headers
            request.AddHeader("Content-Type", "application/json; charset=UTF-8");
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", "Bearer " + accessToken);

            // Body
            request.AddParameter("application/json; charset=UTF-8", jsonPayload, ParameterType.RequestBody);

            // Execute
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            apiResponse = response.Content;

            return apiResponse;
        }


        #endregion 

        #region Inventory Batch Adjust john added on 11-Nov-2024
        public string GET_Inventories(string bearertoken, string db)
        {
            var client = new RestClient("" + BaseUrl + "/api/" + db + "/DFDownload/GetInventory");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_Categories(string bearertoken, string db)
        {
            var client = new RestClient("" + BaseUrl + "/api/" + db + "/DFDownload/GetInventoryCategories");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_InventoryCostAverage(string bearertoken, string db)
        {

            var client = new RestClient("" + BaseUrl + "/api/" + db + "/DFDownload/GetInventoryCostAverage");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string POST_StockAdjustGroup(string bearertoken, string db, string json)
        {

            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/StockAdjustGrouptUnit/Create?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string GET_StockAdjustGroupUnit(string bearertoken, string db)
        {
            var client = new RestClient("" + BaseUrl + "/api/" + db + "/StockAdjustGroupUnit/GetStockAdjustGroupUnit");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string PUT_StockAdjustGroupUnit_by_ID(string bearertoken, string json)
        {
            var client = new RestClient(BaseUrl + "/api/StockAdjustGrouptUnit/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string POST_StockAdjustUnit(string bearertoken, string db, string json)
        {

            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/StockAdjustUnit/Create?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string GET_StockAdjustUnit(string bearertoken, string db)
        {
            var client = new RestClient("" + BaseUrl + "/api/" + db + "/StockAdjustUnit/GetStockAdjustUnit");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_InventoryCostAverageDetail(string bearertoken, string db)
        {
            var client = new RestClient("" + BaseUrl + "/api/" + db + "/InventoryCostAverageDetail/GetInventoryCostAverageDetail");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer" + " " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string PUT_StockAdjustUnit_by_ID(string bearertoken, string json)
        {
            var client = new RestClient(BaseUrl + "/api/StockAdjustUnit/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        //john added on 15-Apr-2025
        public string PUT_InventoryCostAverage(string bearertoken, string db, string json)
        {
            //"url": url + "/api/" + db + "/DFDownload/UpdateInventoryCostAverage",
            var client = new RestClient(BaseUrl + "/api/" + db + "/DFDownload/UpdateInventoryCostAverage");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        //john added on 15-Apr-2025
        public string POST_InventoryCostAverageDetail(string bearertoken, string db, string json)
        {
            //   "url": url + "/api/InventoryCostAverageDetail?clientdb='" + db + "'",
            var client = new RestClient(BaseUrl + "/api/InventoryCostAverageDetail?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        //john added on 15-Apr-2025
        public string POST_InventoryAdjust(string bearertoken, string db, string json)
        {
            //"url": url + "/api/InventoryAdjust?clientdb=" + db,
            var client = new RestClient(BaseUrl + "/api/InventoryAdjust?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        #endregion

        #region Transfer Stock
        public string GET_TransferStockList(string bearertoken, string db)
        {

            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/TransferStockList/GetTransferDetailList");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string POST_TransferStock(string bearertoken, string db, string json)
        {

            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/TransferStockList/Create?ClientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_TransferStock(string bearertoken, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/TransferStock/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_TransferStockDetailedCost(string bearertoken, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/TransferStockDetailedCost");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string POST_StockTransferDetailedCost(string bearertoken, string db, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/TransferStockDetailedCost/Create?ClientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string DELETE_StockTransferDetailedCost(string bearertoken, string db, int transferid)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/TransferStockDetailedCost/Delete?transferid=" + transferid);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            // request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }
        #endregion

        #region Receive Stock

        public string POST_ReceiveStock(string bearertoken, string db, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/ReceiveStockList/Create?ClientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string GET_ReceiveStockList(string bearertoken, string db)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/ReceiveStockList/GetReceiveDetailList");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        //Get_ReceiveStockByReceiveId
        public string GET_ReceiveStockByReceiveId(string bearertoken, string db, int receiveid)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/ReceiveStock/Get_ReceiveStockByReceiveId/" + receiveid);
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;

        }

        public string PUT_ReceiveStock(string bearertoken, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/ReceiveStock/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_ReceiveStockDetailedCost(string bearertoken, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/ReceiveStockDetailedCost/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        ////InventoryCostAverageDetail
        //public string POST_InventoryCostAverageDetail(string bearertoken, string db, string json)
        //{
        //    //BaseUrl = "http://localhost:61760";
        //    var client = new RestClient(BaseUrl + "/api/InventoryCostAverageDetail?ClientDB=" + db);
        //    client.Timeout = -1;
        //    var request = new RestRequest(Method.POST);
        //    request.AddHeader("Authorization", bearertoken);
        //    request.AddHeader("Content-Type", "application/json");
        //    request.AddParameter("application/json", json, ParameterType.RequestBody);
        //    var response = client.Execute(request);
        //    return response.IsSuccessful.ToString();
        //}

        //Return Stock 
        public string POST_ReturnStock(string bearertoken, string db, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/ReturnStockList/Create?ClientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string GET_ReturnStockDetailList(string bearertoken, string db)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/ReturnStockList/GetReturnDetailList");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }
        #endregion

        #region SALES INVOICE
        public string POST_SITransaction(string bearertoken, string db, string json)
        {
            var client = new RestClient(BaseUrl + "/api/SITransaction/Create?clientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string POST_SITranspyment(string bearertoken, string db, string json)
        {
            var client = new RestClient(BaseUrl + "/api/SITranspayment/Create?clientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_SITrans(string bearertoken, string db, string json)
        {

            var client = new RestClient(BaseUrl + "/api/SITrans/Create?update=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();

            //var Client = new RestClient("" + BaseUrl + "/api/WeborderOutofStock/UpdateOutofStockByTiming/" + Dayname + "");
            //Client.Timeout = -1;
            //var request = new RestRequest(Method.PUT);

            //request.AddHeader("Authorization", bearertoken);
            //request.AddHeader("Content-Type", "application/json");
            //request.AddParameter("application/json", json, ParameterType.RequestBody);
            //var response = Client.Execute(request);
            //sAPIResponse = response.IsSuccessful.ToString();
            //return sAPIResponse;

        }

        public string GET_LASTSITrans(string bearertoken, string db)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITrans/Get_LastSITrans");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;

        }

        public string GET_AllTax(string bearertoken, string db)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/Tax/Get_AllTax");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_AllPaymentType(string bearertoken, string db)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/PaymentType/Get_AllPaymentType");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        //Get_SITranspayment_By_TransID
        public string Get_SITranspayment_By_TransID(string bearertoken, string db, int transid)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITranspayment/Get_SITranspayment_By_TransID?TransID=" + transid);
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_LASTSITranspayment(string bearertoken, string db)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITranspayment/Get_LastSITranspayment");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string GET_SITransactionbyDateRange(string bearertoken, string db, DateTime startdate, DateTime enddate)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITransaction/Get_SITransactionByDateRange/" + startdate + "/ " + enddate + "");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }


        public string DELETE_SITransbyTransID(string bearertoken, string db, int transid)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITrans/Delete?transid=" + transid);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string DELETE_SITransdetailbyTransID(string bearertoken, string db, int transid)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITransDetail/Delete_By_TransID?transid=" + transid);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string DELETE_SITranspaymentbyTransID(string bearertoken, string db, int transid)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/SITranspayment/Delete_By_TransID?transid=" + transid);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-Type", "application/json");
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string POST_SITransDetailCosting(string bearertoken, string db, string json)
        {
            var client = new RestClient(BaseUrl + "/api/SITransdetailCosting/Create?clientDB=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }
        #endregion

        #region CRM
        public string PUTPDPAContent(string bearerToken, string data)
        {
            string sAPIResponse = string.Empty;
            //var client = new RestClient("" + BaseUrl + "/api/ICRMSetting/UpdatepdpaContends");
            //bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJuYmYiOjE3MzM3MzIyMDQsImV4cCI6MTczNDMzNzAwNCwiaWF0IjoxNzMzNzMyMjA0fQ.RCA5DHClmKvt801NzcBj5uB-IL7yfXdINvS1Wf8bvqI";
            //var client = new RestClient("http://localhost:61760/api/ICRMSetting/UpdatepdpaContends");
            var client = new RestClient(BaseUrl + "/api/ICRMSetting/UpdatepdpaContends");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", bearerToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", data, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            sAPIResponse = response.IsSuccessful.ToString();
            return sAPIResponse;

        }


        public string GET_PDPA(string bearertoken, string db)
        {

            //var client = new RestClient("http://localhost:61760/api/" + db + "/ICRMSetting/GetpdpaContends/1");
            var client = new RestClient(BaseUrl + "api/" + db + "/ICRMSetting/GetpdpaContends/1");
            client.Timeout = -1;

            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        #endregion



        public string API_POSTCALL_GET_DECRYPTED(string BarToken, string JSONVALUE)
        {

            string sAPIResponse = string.Empty;
            var client = new RestSharp.RestClient("" + BaseUrl + "/api/ICRMAESEncryption/decrypt");
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", BarToken);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json", JSONVALUE, ParameterType.RequestBody);
            var response = client.Execute(request).Content;

            sAPIResponse = response.ToString();
            return sAPIResponse;
        }

        #region KIOSK Landing Image
        public string POST_LandingImage(string bearertoken, string db, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/LandingImage/Create?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_LandingImageByID(string bearertoken, string db, string json)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/LandingImage/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
           
        }

        public string GET_AllLandingImage(string bearertoken, string db)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/LandingImage/GetAllLandingImage");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string DELETE_LandingImageByID(string bearertoken, string db, int id)
        {
            //BaseUrl = "http://localhost:61760";
            var client = new RestClient(BaseUrl + "/api/" + db + "/LandingImage/Delete?id=" + id);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        #endregion

        #region Banner Image
        public string POST_BannerImage(string bearertoken,string db,string json)
        {
            var client = new RestClient(BaseUrl + "/api/BannerImage/Create?clientdb=" + db);
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string PUT_BannerImage(string bearertoken,string json)
        {
            var client = new RestClient(BaseUrl + "/api/BannerImage/Update");
            client.Timeout = -1;
            var request = new RestRequest(Method.PUT);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-type", "application/json");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }

        public string GET_AllBannerImage(string bearertoken,string db)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/BannerImage/GetAllBannerImage");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(request);
            return response.Content;
        }

        public string DELETE_BannerImageByID(string bearertoken,string db,int id)
        {
            var client = new RestClient(BaseUrl + "/api/" + db + "/BannerImage/Delete?id=" + id);
            client.Timeout = -1;
            var request = new RestRequest(Method.DELETE);
            request.AddHeader("Authorization", "Bearer " + bearertoken);
            request.AddHeader("Content-Type", "application/json");
            var response = client.Execute(request);
            return response.IsSuccessful.ToString();
        }
        #endregion

    }

    internal class RestClientOptions
    {
        private string v;

        public RestClientOptions(string v)
        {
            this.v = v;
        }

        public int MaxTimeout { get; set; }
    }

   
}