Skip to content

Instantly share code, notes, and snippets.

View thiagoloureiro's full-sized avatar
🚗
Coding

Thiago Loureiro thiagoloureiro

🚗
Coding
View GitHub Profile
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public class Address
{
public int Id { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
select
C.[Id], C.[Name], C.[Email], C.[Phone],
A.CustomerId, A.Street, A.City, A.Country, A.ZIPCode
from customer C inner join [Address] A on A.CustomerId = C.Id
List<Customer> ret;
using (var db = new SqlConnection(connstring))
{
var sql =
"select C.[Id], C.[Name], C.[Email], C.[Phone], A.CustomerId, A.Street, " +
"A.City, A.Country, A.ZIPCode from customer C " +
"inner join[Address] A on A.CustomerId = C.Id";
ret = db.Query<Customer, Address, Customer>(sql, (customer, address) =>
{
public ConnectionFactory GetConnectionFactory()
{
var connectionFactory = new ConnectionFactory
{
HostName = "localhost",
UserName = "guest",
Password = "guest"
};
return connectionFactory;
}
public IConnection CreateConnection(ConnectionFactory connectionFactory)
{
return connectionFactory.CreateConnection();
}
public QueueDeclareOk CreateQueue(string queueName, IConnection connection)
{
QueueDeclareOk queue;
using (var channel = connection.CreateModel())
{
queue = channel.QueueDeclare(queueName, false, false, false, null);
}
return queue;
}
public bool WriteMessageOnQueue(string message, string queueName, IConnection connection)
{
using (var channel = connection.CreateModel())
{
channel.BasicPublish(string.Empty, queueName, null, Encoding.ASCII.GetBytes(message));
}
return true;
}
public string RetrieveSingleMessage(string queueName, IConnection connection)
{
BasicGetResult data;
using (var channel = connection.CreateModel())
{
data = channel.BasicGet(queueName, true);
}
return data != null ? System.Text.Encoding.UTF8.GetString(data.Body) : null;
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace SwaggerAspnetCore
{
public class Startup
{
public Startup(IConfiguration configuration)