23 lines
No EOL
601 B
C#
23 lines
No EOL
601 B
C#
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using Dapper;
|
|
using Website.Models;
|
|
|
|
namespace Website.Data
|
|
{
|
|
public class BlogRepository
|
|
{
|
|
private readonly DatabaseProvider _dbProvider;
|
|
|
|
public BlogRepository(DatabaseProvider dbProvider) => _dbProvider = dbProvider;
|
|
|
|
public async Task<BlogPost> GetPostAsync(int id) {
|
|
const string query = "SELECT * FROM blog_posts WHERE post_id=@id";
|
|
using (var connection = _dbProvider.NewConnection()) {
|
|
connection.Open();
|
|
var result = await connection.QueryAsync<BlogPost>(query, new{id});
|
|
return result.FirstOrDefault();
|
|
}
|
|
}
|
|
}
|
|
} |