zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.Application/Queries/Ordering/OrderQueries.cs

28 lines
922 B
C#
Raw Normal View History

2023-12-05 09:22:48 +00:00
using Dapper;
using System.Data;
using System.Data.SqlClient;
namespace ZeroFramework.DeviceCenter.Application.Queries.Ordering
{
public class OrderQueries(string connectionString) : IOrderQueries
{
private readonly string _connectionString = connectionString;
public async Task<OrderViewModel> GetOrderAsync(Guid id)
{
using IDbConnection connection = SqlClientFactory.Instance.CreateConnection();
connection.ConnectionString = _connectionString;
connection.Open();
dynamic result = await connection.QueryFirst<dynamic>(@"SELECT * FROM [Order] WHERE Id=@Id", new { id });
if (!result.AsList().Any())
{
throw new KeyNotFoundException();
}
return new OrderViewModel { OrderId = result.Id, BuyerId = result.BuyerId, CreationTime = result.CreationTime };
}
}
}