/// <summary>
        /// Convert an object in to JSON string
        /// </summary>
        /// <param name="req">Object Request</param>
        /// <returns>Json String</returns>
        private static string GetRequestJSON(Model.MailChimpContactCreateBatchRequest req)
        {
            string productData            = string.Empty;
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Model.MailChimpContactCreateBatchRequest));
            MemoryStream ms = null;

            ms = new MemoryStream();
            js.WriteObject(ms, req);
            ms.Position = 0;
            StreamReader sr = new StreamReader(ms);

            productData = sr.ReadToEnd();
            byte[] data = Encoding.ASCII.GetBytes(productData);
            return(productData);
        }
        /// <summary>
        /// Create json string as per the Mail chimp api
        /// </summary>
        /// <param name="marketingListID">Marketing list id from config record</param>
        /// <param name="members">Entity Collection marketing list members</param>
        /// <returns>json string</returns>
        private static string CreateBatchJSON(string mailChimpMarketingListID, EntityCollection members, ITracingService tracer)
        {
            string jsonData = string.Empty;

            Model.MailChimpContactCreateBatchRequest requestObject = new Model.MailChimpContactCreateBatchRequest();
            List <Model.Operation> operationlist = new List <Model.Operation>();

            foreach (var memberEntity in members.Entities)
            {
                Model.Operation operation  = new Model.Operation();
                string          subscribed = "subscribed";
                string          firstname  = string.Empty;
                string          lastname   = string.Empty;
                if (memberEntity.Contains("firstname"))
                {
                    firstname = memberEntity.Attributes["firstname"].ToString();
                }

                if (memberEntity.Contains("lastname"))
                {
                    lastname = memberEntity.Attributes["lastname"].ToString();
                }
                if (!string.IsNullOrEmpty(firstname))
                {
                    if (!string.IsNullOrEmpty(lastname))
                    {
                        tracer.Trace("First name and last name present");
                        operation.body = "{\"email_address\":\"" + memberEntity.Attributes["emailaddress1"] + "\",\"status\":\"" + subscribed + "\",\"merge_fields\":{\"FNAME\":\"" + firstname + "\",\"LNAME\":\"" + lastname + "\"}}";
                        tracer.Trace("operation.body: " + operation.body);
                    }
                    else
                    {
                        tracer.Trace("First name present");
                        operation.body = "{\"email_address\":\"" + memberEntity.Attributes["emailaddress1"] + "\",\"status\":\"" + subscribed + "\",\"merge_fields\":{\"FNAME\":\"" + firstname + "\"}}";
                        tracer.Trace("operation.body: " + operation.body);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(lastname))
                    {
                        tracer.Trace(" last name present");
                        operation.body = "{\"email_address\":\"" + memberEntity.Attributes["emailaddress1"] + "\",\"status\":\"" + subscribed + "\",\"merge_fields\":{\"LNAME\":\"" + lastname + "\"}}";
                        tracer.Trace("operation.body: " + operation.body);
                    }
                    else
                    {
                        tracer.Trace("First name and last name not present");
                        operation.body = "{\"email_address\":\"" + memberEntity.Attributes["emailaddress1"] + "\",\"status\":\"" + subscribed + "\"}";
                        tracer.Trace("operation.body: " + operation.body);
                    }
                }

                //// Create request
                tracer.Trace("Create request");
                operation.method = "POST";
                operation.path   = "lists/" + mailChimpMarketingListID + "/members";
                tracer.Trace("Operation path: " + operation.path.ToString());
                operationlist.Add(operation);
            }

            requestObject.operations = operationlist;

            jsonData = GetRequestJSON(requestObject);
            return(jsonData);
        }