Ejemplo n.º 1
0
        public bool AddTarifAgent(TarifAgentModel tarif)
        {
            if (tarif.Id == null)
            {
                using (SqlConnection conn = new SqlConnection(_connectionStringAdmin))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("dbo.AddTarifAgent", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@agentId", tarif.AgentId);
                    cmd.Parameters.AddWithValue("@tarifId", tarif.TarifId);
                    cmd.Parameters.AddWithValue("@tarifSum", tarif.TarifSum);
                    return(Convert.ToBoolean(cmd.ExecuteScalar()));
                }
            }
            else
            {
                using (SqlConnection conn = new SqlConnection(_connectionStringAdmin))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("dbo.ChangeTarifAgent", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@id", tarif.Id);
                    cmd.Parameters.AddWithValue("@tarifSum", tarif.TarifSum);
                    return(Convert.ToBoolean(cmd.ExecuteScalar()));
                }
            }
        }
Ejemplo n.º 2
0
        public List <TarifAgentModel> GetAgentTarifs()
        {
            List <TarifAgentModel> agentTarifs = new List <TarifAgentModel>();

            using (SqlConnection conn = new SqlConnection(_connectionStringAdmin))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("dbo.GetAgentTarifs", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    TarifAgentModel agentTarif = new TarifAgentModel();
                    agentTarif.Id        = reader["Id"] != DBNull.Value ? Convert.ToInt32(reader["Id"]) : 0;
                    agentTarif.TarifId   = reader["TarifId"] != DBNull.Value ? Convert.ToInt32(reader["TarifId"]) : 0;
                    agentTarif.AgentId   = reader["AgentId"] != DBNull.Value ? Convert.ToInt32(reader["AgentId"]) : 0;
                    agentTarif.TarifSum  = reader["TarifSum"] != DBNull.Value ? Convert.ToInt32(reader["TarifSum"]) : 0;
                    agentTarif.TarifName = reader["TarifName"] != DBNull.Value ? Convert.ToString(reader["TarifName"]) : string.Empty;
                    agentTarif.AgentName = reader["AgentName"] != DBNull.Value ? Convert.ToString(reader["AgentName"]) : string.Empty;
                    agentTarifs.Add(agentTarif);
                }
            }
            return(agentTarifs);
        }