Files
SIG-CM/src/SIGCM.Infrastructure/Repositories/ImageRepository.cs

34 lines
1.1 KiB
C#
Raw Normal View History

using Dapper;
using SIGCM.Domain.Entities;
using SIGCM.Domain.Interfaces;
using SIGCM.Infrastructure.Data;
namespace SIGCM.Infrastructure.Repositories;
public class ImageRepository : IImageRepository
{
private readonly IDbConnectionFactory _connectionFactory;
public ImageRepository(IDbConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
}
public async Task AddAsync(ListingImage image)
{
using var conn = _connectionFactory.CreateConnection();
var sql = @"
INSERT INTO ListingImages (ListingId, Url, IsMainInfo, DisplayOrder)
VALUES (@ListingId, @Url, @IsMainInfo, @DisplayOrder)";
await conn.ExecuteAsync(sql, image);
}
public async Task<IEnumerable<ListingImage>> GetByListingIdAsync(int listingId)
{
using var conn = _connectionFactory.CreateConnection();
return await conn.QueryAsync<ListingImage>(
"SELECT * FROM ListingImages WHERE ListingId = @ListingId ORDER BY DisplayOrder",
new { ListingId = listingId });
}
}