예제 #1
0
        public bool SaveLead(Lead obj)
        {
            bool result = false;

            if (obj == null)
            {
                throw new Exception("Object Lead can not be null");
            }
            else if (string.IsNullOrEmpty(obj.Email))
            {
                throw new Exception("Property E-mail can not be null or empty");
            }
            else
            {
                logServices.LogTrace("===================================================");
                logServices.LogTrace("START METHOD SAVELEAD");
                logServices.LogTrace("===================================================");
                try
                {
                    string response = ComunicationWihApi(RequestMethodType.POST, RequestSignature.CONVERSIONS, ConvertDataToPost(obj));

                    if (!string.IsNullOrEmpty(response))
                    {
                        logServices.LogTrace("DESERIALIZE RETURN TO CHECK");
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        dynamic json   = serializer.Deserialize(response, typeof(object));
                        var     status = (string)json["status"];

                        if (status.Equals("sucesso"))
                        {
                            logServices.LogTrace("SUCCESS");
                            result = true;
                        }
                        else
                        {
                            logServices.LogTrace("OPS! CHECK RESPONSE");
                            logServices.LogTrace(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logServices.LogError(ex, "Error call Lahar API");
                    throw new Exception("Error call ComunicationWihApi", ex);
                }
            }

            logServices.LogTrace("END METHOD SAVELEAD");
            return(result);
        }