public Object C2CCallPost([FromBody] c2cinput c2ci)
        {
            string    sJSONResponse  = "";
            DataTable dt_AppType     = new DataTable();
            string    ServerDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            int       a         = 0;
            string    c2c_Query = "";
            c2coutput c2copt    = new c2coutput();

            try
            {
                cnn.Open();
                c2c_Query = "insert into C2CAPI_Registration(SRNo,CallerId,AgentNo,EmployeeCode,CreatedBy,CreatedOn,IsDeleted,IsActive) values('" + c2ci.k_number + "','" + c2ci.caller_id + "','" + c2ci.agent_number + "','" + c2ci.EmployeeCode + "','" + c2ci.CreatedBy + "','" + ServerDateTime + "',0,1) SELECT @@IDENTITY;";
                SqlCommand c2c_cmd = new SqlCommand(c2c_Query, cnn);
                a             = Convert.ToInt32(c2c_cmd.ExecuteScalar());
                c2copt.status = "Success";
            }
            catch (Exception ex)
            {
                c2copt.status = "fail";
            }
            finally
            {
                cnn.Close();
            }

            sJSONResponse = JsonConvert.SerializeObject(c2copt);

            return(sJSONResponse);
        }
        public Object C2CCallDelete([FromBody] c2cinput c2ci)
        {
            c2coutput  c2copt         = new c2coutput();
            SqlCommand command        = cnn.CreateCommand();
            string     ServerDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

            try
            {
                cnn.Close();
                cnn.Open();
                SqlTransaction transaction;
                transaction         = cnn.BeginTransaction("SampleTransaction");
                command.Connection  = cnn;
                command.Transaction = transaction;
                try
                {
                    command.CommandText = "delete from C2CAPI_Registration where EmployeeCode='" + c2ci.EmployeeCode + "' ";
                    command.ExecuteNonQuery();

                    transaction.Commit();
                    c2copt.status = "Success";
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
                finally
                {
                }
            }
            catch (Exception ec)
            {
                c2copt.status = "fail";
            }

            string sJSONResponse = JsonConvert.SerializeObject(c2copt);

            return(sJSONResponse);
        }
        public Object C2CCall([FromBody] c2cinput c2ci)
        {
            c2coutput mdo            = new c2coutput();
            string    sJSONResponse  = "";
            DataTable dt_AppType     = new DataTable();
            string    ServerDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            int       a             = 0;
            string    c2ccall_Query = "";

            DataTable dt_C2CcallDetails = getdata(string.Format("select SRNo,CallerId,AgentNo from C2CAPI_Registration where EmployeeCode='{0}' and IsActive=1", c2ci.EmployeeCode));

            string Authorization = "1652dcb2-7e50-4644-b441-38d832e90dc0";
            var    apikey        = "lF4vZUSwA8Jab0ABWsITtxwM1ZwL6h2jZDdCTX30";

            //C2CData csda = new C2CData();
            //csda.k_number = c2ci.k_number;
            //csda.agent_number = c2ci.agent_number;
            //csda.customer_number = c2ci.CustomerNumber;
            //csda.caller_id = c2ci.caller_id;

            C2CData csda = new C2CData();

            csda.k_number        = dt_C2CcallDetails.Rows[0]["SRNo"].ToString();
            csda.agent_number    = dt_C2CcallDetails.Rows[0]["AgentNo"].ToString();
            csda.customer_number = c2ci.CustomerNumber;
            csda.caller_id       = dt_C2CcallDetails.Rows[0]["CallerId"].ToString();


            string strResult = string.Empty;

            string        url              = "https://kpi.knowlarity.com/Basic/v1/account/call/makecall";
            ASCIIEncoding encoding         = new ASCIIEncoding();
            var           serializedObject = Newtonsoft.Json.JsonConvert.SerializeObject(csda);

            byte[]         byteArray  = Encoding.UTF8.GetBytes(serializedObject);
            HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);

            webrequest.Method                   = "POST";
            webrequest.ContentType              = "application/json";
            webrequest.ContentLength            = byteArray.Length;
            webrequest.Headers["Authorization"] = Authorization;
            webrequest.Headers["x-api-key"]     = apikey;
            // get stream data out of webrequest object
            Stream newStream = webrequest.GetRequestStream();

            newStream.Write(byteArray, 0, byteArray.Length);
            newStream.Close();
            HttpWebResponse webresponse      = (HttpWebResponse)webrequest.GetResponse();
            Encoding        enc              = System.Text.Encoding.UTF8;
            StreamReader    loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);

            strResult = loResponseStream.ReadToEnd();
            loResponseStream.Close();
            webresponse.Close();

            DataTable dtResult = new DataTable();

            string result  = strResult.Remove(0, 11);
            int    maxlmt  = result.Count();
            string result2 = result.Remove(maxlmt - 1);

            string[] result3 = result2.Split(',');

            ArrayList arl = new ArrayList();

            foreach (string item in result3)
            {
                arl.Add(item);
            }

            string message = "";
            string call_id = "";


            try
            {
                message = arl[1].ToString().Replace("message", "");
                message = message.Replace(":", "");
                message = message.Replace(@"\\", "");
                call_id = arl[2].ToString().Replace("call_id", "");
                call_id = call_id.Replace(":", "");
                call_id = call_id.Replace("\\", "");
            }
            catch (Exception ec)
            {
                message = arl[0].ToString().Replace("message", "");
                message = message.Replace(":", "");
                message = message.Replace(@"\\", "");
            }



            try
            {
                cnn.Open();
                c2ccall_Query = "insert into C2CAPI_makecall(SRNo,CallerId,AgentNo,EmployeeCode,callid,CreatedBy,CreatedOn,IsDeleted,IsActive) values('" + c2ci.k_number + "','" + c2ci.caller_id + "','" + c2ci.agent_number + "','" + c2ci.EmployeeCode + "','" + c2ci.CustomerNumber + "','" + c2ci.CreatedBy + "','" + ServerDateTime + "',0,1)";
                SqlCommand tm_cmd = new SqlCommand(c2ccall_Query, cnn);
                a          = Convert.ToInt32(tm_cmd.ExecuteNonQuery());
                mdo.status = "Success";
                mdo.value  = GetOutputMsg(message, call_id);
            }
            catch (Exception ex)
            {
                mdo.status = "fail";
            }
            finally
            {
                cnn.Close();
            }

            sJSONResponse = JsonConvert.SerializeObject(mdo);

            return(sJSONResponse);
        }