private void ProcessData(AgentDataNew agent)
        {
            var requestdata = RequestBody(agent);

            Console.WriteLine("requestdata :: " + requestdata);
            if (requestdata == null)
            {
                return;
            }

            int?idprofile    = null;
            var taspenApi    = new TaspenApi();
            var responsedata = taspenApi.CreateNewAgent(requestdata);

            Console.WriteLine("responsedata :: " + responsedata);
            if (responsedata != null)
            {
                var agentDto = JsonConvert.DeserializeObject <AgentDto>(responsedata);
                if (agentDto?.listAgentProfile != null)
                {
                    idprofile = agentDto.listAgentProfile.id;
                }
            }

            var payeeid = int.Parse(agent.PayeeID, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);

            var data = new LogAgentDataNew()
            {
                IDAGENT      = payeeid,
                CREATEDDATE  = DateTime.Now,
                REQUESTDATA  = requestdata,
                RESPONSEDATA = responsedata,
                IDPROFILE    = idprofile
            };

            Console.WriteLine("IDAGENT : " + payeeid);
            Console.WriteLine("IDPROFILE : " + idprofile);
            var logDao = new LogAgentDataNewDao();

            logDao.Create(data);
        }
Beispiel #2
0
        public void Create(LogAgentDataNew entity)
        {
            SqlConnectionStringBuilder builder = ConnectionStringBuilder.GetConnectionStringBuilder();

            using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
            {
                string sql = "INSERT INTO LOG_AGENTDATANEW(IDAGENT, REQUESTDATA,RESPONSEDATA,IDPROFILE) VALUES(@p_idagent, @p_requestdata,@p_responsedata,@p_idprofile)";

                SqlCommand cmd = new SqlCommand(sql, connection);
                //open connection
                connection.Open();

                cmd.Parameters.Add("@p_idagent", SqlDbType.Int).Value          = entity.IDAGENT;
                cmd.Parameters.Add("@p_requestdata", SqlDbType.VarChar).Value  = entity.REQUESTDATA;
                cmd.Parameters.Add("@p_responsedata", SqlDbType.VarChar).Value = entity.RESPONSEDATA;
                cmd.Parameters.Add("@p_idprofile", SqlDbType.Int).Value        = entity.IDPROFILE;
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();

                connection.Close();
            }
        }
Beispiel #3
0
        public LogAgentDataNew FindById(int id)
        {
            SqlConnectionStringBuilder builder = ConnectionStringBuilder.GetConnectionStringBuilder();

            try
            {
                //sql connection object
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    //retrieve the SQL Server instance version
                    string query = @"SELECT e.IDAGENT, e.REQUESTDATA, e.RESPONSEDATA, e.IDPROFILE, e.CREATEDDATE
                    FROM LOG_AGENTDATANEW e
                    WHERE e.IDAGENT = @p_id ;";
                    //define the SqlCommand object
                    SqlCommand cmd = new SqlCommand(query, connection);

                    var pid = new SqlParameter("p_id", SqlDbType.Int);
                    pid.Value = id;
                    cmd.Parameters.Add(pid);

                    //open connection
                    connection.Open();

                    //execute the SQLCommand
                    SqlDataReader dr = cmd.ExecuteReader();

                    //check if there are records
                    var result = new List <LogAgentDataNew>();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            var data = new LogAgentDataNew();
                            data.IDAGENT      = dr.GetInt32(0);
                            data.REQUESTDATA  = SafeGetString(dr, 1);
                            data.RESPONSEDATA = SafeGetString(dr, 2);
                            data.IDPROFILE    = SafeGetInt(dr, 3);
                            data.CREATEDDATE  = SafeGetDatetime(dr, 4);


                            result.Add(data);
                        }
                    }

                    //close data reader
                    dr.Close();

                    //close connection
                    connection.Close();
                    if (result.Count > 0)
                    {
                        return(result.FirstOrDefault());
                    }
                }
            }
            catch (Exception ex)
            {
                //display error message
                Console.WriteLine("Exception: " + ex.Message);
            }
            return(null);
        }