/// <summary>
        /// Create new scan request
        /// </summary>
        /// <returns></returns>
        public string CreateNewScanRequest(string projectId, string projectName, string url)
        {
            string responseIssueId = string.Empty;
            try
            {
                string tracekrIdZAP = ConfigurationSettings.AppSettings["tracker_secuirtyscan:zap"];

                string tracekrIdSSL = ConfigurationSettings.AppSettings["tracker_secuirtyscan:ssl"];

                Issue issueZAP = new Issue();
                issueZAP.subject = "ZAP Security Scan for Project:" + projectName;
                issueZAP.status_id = 1;//1 = new
                issueZAP.project_id = 65;//project id of deployment
                issueZAP.description = "ZAP Scan Created at:  " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
                responseIssueId = PostData.PostMethod(issueZAP, "2", tracekrIdZAP) + ",";

                Issue issueSSL = new Issue();
                issueSSL.subject = "SSL Security Scan for Project:" + projectName;
                issueSSL.status_id = 1;//1 = new
                issueSSL.project_id = 65;//project id of deployment
                issueSSL.description = "SSL Scan Created at:  " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
                responseIssueId += PostData.PostMethod(issueSSL, "2", tracekrIdSSL);

                return responseIssueId;
            }
            catch (Exception ex)
            {
                Logger.Error("SecurityScan.CreateNewScanRequest" + ex.ToString());
                return "Excepton: " + ex.ToString();
            }
        }
        //to create new issue in any project
        public string Post(Issue data)
        {
            string result = string.Empty;
            CreateIssueService cis = new CreateIssueService();
            result = cis.CreateIssue(data);
               if(result != null)
               {
               return result;

               }
               return null;
        }
        //to create new issue in any project
        public HttpResponseMessage Post(Issue data)
        {
            try
            {
                int redmineUserId;
                AccountsServices ac = new AccountsServices();
                string auth = ac.CheckToken(Request);
                if (string.IsNullOrEmpty(auth))
                    return Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized access");
                else if (auth.Contains("Exception"))
                    return Request.CreateResponse(HttpStatusCode.Unauthorized, "Authentication error!! Please try again");
                else
                    int.TryParse(auth, out redmineUserId);

                CreateUpdateIssue cup = new CreateUpdateIssue();
                var result = cup.CreateIssue(data, redmineUserId.ToString());
                return Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "InternalServerError");
            }
            //    return finalString;
        }
        public static string PostMethod(Issue data, string priorityId, string trackerId)
        {
            try
            {
                String finalString = "";

                XmlDocument xmlDoc = new XmlDocument();
                XmlNode rootNode = xmlDoc.CreateElement("issue");
                xmlDoc.AppendChild(rootNode);

                XmlNode idNode = xmlDoc.CreateElement("project_id");
                idNode.InnerText = data.project_id.ToString();//pass project id
                rootNode.AppendChild(idNode);

                XmlNode nameNode = xmlDoc.CreateElement("subject");
                nameNode.InnerText = data.subject;
                rootNode.AppendChild(nameNode);

                XmlNode identifierNode = xmlDoc.CreateElement("priority_id");
                identifierNode.InnerText = priorityId;
                rootNode.AppendChild(identifierNode);

                XmlNode statusNode = xmlDoc.CreateElement("status_id");
                statusNode.InnerText = data.status_id.ToString();
                rootNode.AppendChild(statusNode);

                XmlNode trackerNode = xmlDoc.CreateElement("tracker_id");
                trackerNode.InnerText = trackerId;
                rootNode.AppendChild(trackerNode);

                string XmlizedString = "";
                using (StringWriter sw = new StringWriter())
                {
                    using (XmlTextWriter tx = new XmlTextWriter(sw))
                    {
                        xmlDoc.WriteTo(tx);
                        XmlizedString = sw.ToString();
                    }
                }
                finalString = XmlizedString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
                string postirl = System.Configuration.ConfigurationManager.AppSettings["hostUrl"] + "issues.xml?key=" + System.Configuration.ConfigurationManager.AppSettings["apiKey"];
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postirl);
                byte[] bytes;
                bytes = System.Text.Encoding.ASCII.GetBytes(finalString);
                request.ContentType = "application/xml; encoding='utf-8'";
                request.ContentLength = bytes.Length;
                request.Method = "POST";
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                HttpWebResponse response;
                response = (HttpWebResponse)request.GetResponse();
                Uri res = (Uri)response.ResponseUri;
                string resLocation = response.Headers["Location"].ToString();
                string issueIdCreated = resLocation.Split(new string[] { "issues/" }, StringSplitOptions.None)[1];
                return issueIdCreated;
            }
            catch (Exception ex)
            {
                Logger.Error("PostData.PostMethod" + ex.ToString());
                return string.Empty;
            }
        }
        public string CreateIssue(Issue data)
        {
            String finalString = "";

            XmlDocument xmlDoc = new XmlDocument();
            XmlNode rootNode = xmlDoc.CreateElement("issue");
            xmlDoc.AppendChild(rootNode);

            XmlNode idNode = xmlDoc.CreateElement("project_id");
            idNode.InnerText = data.project_id.ToString();//pass project id
            rootNode.AppendChild(idNode);

            XmlNode nameNode = xmlDoc.CreateElement("subject");
            nameNode.InnerText = data.subject;
            rootNode.AppendChild(nameNode);

            try
            {
                XmlNode identifierNode = xmlDoc.CreateElement("priority_id");
                identifierNode.InnerText = data.priority_id.ToString();
                rootNode.AppendChild(identifierNode);
            }
            catch { }
            XmlNode statusNode = xmlDoc.CreateElement("status_id");
            statusNode.InnerText = data.status_id.ToString();
            rootNode.AppendChild(statusNode);

            XmlNode trackerNode = xmlDoc.CreateElement("tracker_id");
            trackerNode.InnerText = data.tracker_id.ToString();
            rootNode.AppendChild(trackerNode);
            try
            {
                XmlNode deployNode = xmlDoc.CreateElement("due_date");
                deployNode.InnerText = data.due_date.ToString();
                rootNode.AppendChild(deployNode);
            }
            catch { }

            XmlNode custom_fieldsNode = xmlDoc.CreateElement("custom_fields");
            XmlAttribute attribute = xmlDoc.CreateAttribute("type");
            attribute.Value = "array";
            custom_fieldsNode.Attributes.Append(attribute);
            try
            {
                foreach (var v in data.custom_fields)
                {

                    XmlNode custom_fieldNode = xmlDoc.CreateElement("custom_field");

                    XmlAttribute attribute1 = xmlDoc.CreateAttribute("id");
                    attribute1.Value = v.id.ToString();
                    custom_fieldNode.Attributes.Append(attribute1);

                    XmlAttribute attribute2 = xmlDoc.CreateAttribute("name");
                    attribute2.Value = v.name;
                    custom_fieldNode.Attributes.Append(attribute2);

                    XmlNode valueNode = xmlDoc.CreateElement("value");
                    valueNode.InnerText = v.value;
                    custom_fieldNode.AppendChild(valueNode);

                    custom_fieldsNode.AppendChild(custom_fieldNode);

                }
                rootNode.AppendChild(custom_fieldsNode);
            }
            catch { }
            string XmlizedString = "";
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter tx = new XmlTextWriter(sw))
                {
                    xmlDoc.WriteTo(tx);
                    XmlizedString = sw.ToString();
                }
            }

            finalString = XmlizedString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
            string postirl = System.Configuration.ConfigurationManager.AppSettings["hostUrl"] + "issues.xml?key=" + System.Configuration.ConfigurationManager.AppSettings["apiKey"];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postirl);
            byte[] bytes;
            bytes = System.Text.Encoding.ASCII.GetBytes(finalString);
            request.ContentType = "application/xml; encoding='utf-8'";
            request.ContentLength = bytes.Length;
            request.Method = "POST";
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream responseStream = response.GetResponseStream();
                string responseStr = new StreamReader(responseStream).ReadToEnd();
                return responseStr;
            }
            return null;
        }
 private static string CreateIssue(string name, string url, int status)
 {
     try
     {
         Issue iv = new Issue();
         iv.subject = "Site Down for Project: " + name;
         Tracker t = new Tracker();
         t.id = 15;//15 for incident request
         t.name = "Incident Request";
         iv.tracker = t;//tracker for incident request
         iv.status_id = status;//1 = new , 5 = closed
         iv.project_id = 65;//project id of deployment
         iv.priority_id = 3;//High Priority
         iv.description = "Unable to ping website :" + url + ".  Website down at: " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
         string responseString = PostData.PostMethod(iv, "3", "15");
         return responseString;
     }
     catch (Exception ex)
     {
         ErrorLogging.WriteErrorLog(ex);
         return string.Empty;
     }
 }
        public static string GenerateXml(Issue data)
        {
            String finalString = "";
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                XmlNode rootNode = xmlDoc.CreateElement("issue");
                xmlDoc.AppendChild(rootNode);

                XmlNode idNode = xmlDoc.CreateElement("project_id");
                idNode.InnerText = data.project_id.ToString();//pass project id
                rootNode.AppendChild(idNode);

                XmlNode nameNode = xmlDoc.CreateElement("subject");
                nameNode.InnerText = data.subject;
                rootNode.AppendChild(nameNode);

                XmlNode identifierNode = xmlDoc.CreateElement("priority_id");
                identifierNode.InnerText = data.priority_id.ToString();
                rootNode.AppendChild(identifierNode);

                XmlNode statusNode = xmlDoc.CreateElement("status_id");
                statusNode.InnerText = data.status_id.ToString();
                rootNode.AppendChild(statusNode);

                XmlNode trackerNode = xmlDoc.CreateElement("tracker_id");
                trackerNode.InnerText = data.tracker_id.ToString();
                rootNode.AppendChild(trackerNode);
                if (data.due_date != null)
                {
                    XmlNode deployNode = xmlDoc.CreateElement("due_date");
                    deployNode.InnerText = data.due_date.ToString();
                    rootNode.AppendChild(deployNode);
                }

                XmlNode custom_fieldsNode = xmlDoc.CreateElement("custom_fields");
                XmlAttribute attribute = xmlDoc.CreateAttribute("type");
                attribute.Value = "array";
                custom_fieldsNode.Attributes.Append(attribute);

                if (data.custom_fields != null)
                {
                    foreach (var v in data.custom_fields)
                    {

                        XmlNode custom_fieldNode = xmlDoc.CreateElement("custom_field");

                        XmlAttribute attribute1 = xmlDoc.CreateAttribute("id");

                        attribute1.Value = v.id.ToString();
                        custom_fieldNode.Attributes.Append(attribute1);

                        XmlAttribute attribute2 = xmlDoc.CreateAttribute("name");
                        attribute2.Value = v.name;
                        custom_fieldNode.Attributes.Append(attribute2);

                        XmlNode valueNode = xmlDoc.CreateElement("value");
                        valueNode.InnerText = v.value;
                        custom_fieldNode.AppendChild(valueNode);

                        custom_fieldsNode.AppendChild(custom_fieldNode);

                    }
                    rootNode.AppendChild(custom_fieldsNode);
                }

                string XmlizedString = "";
                using (StringWriter sw = new StringWriter())
                {
                    using (XmlTextWriter tx = new XmlTextWriter(sw))
                    {
                        xmlDoc.WriteTo(tx);
                        XmlizedString = sw.ToString();
                    }
                }

                finalString = XmlizedString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
                return finalString;
            }
            catch (Exception ex)
            {
                Logger.Debug("CreateUpdateIssue.UpdateIssue CreateEstimateXML: " + finalString);
                Logger.Error("CreateUpdateIssue.UpdateIssue Exception" + ex.ToString());
                return null;
            }
        }
        public string UpdateIssue(Issue data, string redmineUserId)
        {
            string postirl = string.Empty;
            string finalString = string.Empty;
            try
            {
                finalString = GenerateXml(data);
                string getUserApiKey = "Select [RedmineApiKey] from [Users] where [RedmineUserId] = '" + redmineUserId + "'";
                string UserApiKey = dc.GetSingleCell(getUserApiKey);
                postirl = System.Configuration.ConfigurationManager.AppSettings["hostUrl"] + "issues/" + data.id + ".xml?key=" + UserApiKey;// System.Configuration.ConfigurationManager.AppSettings["apiKey"];
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postirl);
                byte[] bytes;
                bytes = System.Text.Encoding.ASCII.GetBytes(finalString);
                request.ContentType = "application/xml; encoding='utf-8'";
                request.ContentLength = bytes.Length;
                request.Method = "PUT";
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                HttpWebResponse response;
                response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream responseStream = response.GetResponseStream();
                    string responseStr = new StreamReader(responseStream).ReadToEnd();
                    return responseStr;
                }
                else
                {
                    Logger.Debug("CreateUpdateIssue.UpdateIssue Url: " + postirl);
                    Logger.Debug("CreateUpdateIssue.UpdateIssue XML: " + finalString);
                    return null;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CreateUpdateIssue.UpdateIssue Exception" + ex.ToString());
                Logger.Debug("CreateUpdateIssue.UpdateIssue Url: " + postirl);
                Logger.Debug("CreateUpdateIssue.UpdateIssue XML: " + finalString);
                return null;
            }
        }
        public string Copy(Issue data, int childpro_id)
        {
            //   string result = "";
            String finalString = "";
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode rootNode = xmlDoc.CreateElement("issue");
            xmlDoc.AppendChild(rootNode);

            XmlNode idNode = xmlDoc.CreateElement("project_id");
            idNode.InnerText = childpro_id.ToString();//pass project id
            rootNode.AppendChild(idNode);

            XmlNode nameNode = xmlDoc.CreateElement("subject");
            nameNode.InnerText = data.subject;
            rootNode.AppendChild(nameNode);

            XmlNode identifierNode = xmlDoc.CreateElement("priority_id");
            Priority p = new Priority();
            p = data.priority;
            identifierNode.InnerText = p.id.ToString();
            rootNode.AppendChild(identifierNode);

            XmlNode statusNode = xmlDoc.CreateElement("status_id");
            Status st = new Status();
            st = data.status;
            statusNode.InnerText = st.id.ToString();
            rootNode.AppendChild(statusNode);

            XmlNode trackerNode = xmlDoc.CreateElement("tracker_id");
            Tracker tk = new Tracker();
            tk = data.tracker;
            tk.id = 2;
            trackerNode.InnerText = tk.id.ToString();

            rootNode.AppendChild(trackerNode);
            try
            {
                XmlNode DuedateNode = xmlDoc.CreateElement("due_date");
                DuedateNode.InnerText = data.due_date.ToString();
                rootNode.AppendChild(DuedateNode);
            }
            catch
            {
                XmlNode DuedateNode = xmlDoc.CreateElement("due_date");
                DuedateNode.InnerText = "2015-12-12";
                rootNode.AppendChild(DuedateNode);
            }

            XmlNode custom_fieldsNode = xmlDoc.CreateElement("custom_fields");
            XmlAttribute attribute = xmlDoc.CreateAttribute("type");
            attribute.Value = "array";
            custom_fieldsNode.Attributes.Append(attribute);

            List<CustomField> cf = new List<CustomField>();
            cf = data.custom_fields;
            foreach (var v in cf)
            {

                XmlNode custom_fieldNode = xmlDoc.CreateElement("custom_field");

                XmlAttribute attribute1 = xmlDoc.CreateAttribute("id");
                attribute1.Value = v.id.ToString();
                custom_fieldNode.Attributes.Append(attribute1);

                XmlAttribute attribute2 = xmlDoc.CreateAttribute("name");
                attribute2.Value = v.name;
                custom_fieldNode.Attributes.Append(attribute2);

                XmlNode valueNode = xmlDoc.CreateElement("value");
                valueNode.InnerText = v.value;
                custom_fieldNode.AppendChild(valueNode);

                custom_fieldsNode.AppendChild(custom_fieldNode);

            }
            rootNode.AppendChild(custom_fieldsNode);

            string XmlizedString = "";
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter tx = new XmlTextWriter(sw))
                {
                    xmlDoc.WriteTo(tx);
                    XmlizedString = sw.ToString();
                }
            }

            finalString = XmlizedString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
            //    finalString = XmlizedString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
            //    string postirl = "http://10.97.85.87/redmine/issues.xml?key=0a23ab709cc2fc57d83f94a78016a57feef4d488";
            string posturl =    System.Configuration.ConfigurationManager.AppSettings["hostUrl"] + "issues.xml?key=" + System.Configuration.ConfigurationManager.AppSettings["apiKey"];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(posturl);
            byte[] bytes;
            //       finalString = "<issue><project_id>65</project_id><subject>Testing47</subject><priority_id>2</priority_id><status_id>1</status_id><tracker_id>14</tracker_id></issue>";
            bytes = System.Text.Encoding.ASCII.GetBytes(finalString);
            request.ContentType = "application/xml; encoding='utf-8'";
            request.ContentLength = bytes.Length;
            request.Method = "POST";
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
            Uri res = (Uri)response.ResponseUri;

            return response.StatusCode.ToString();
        }