initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.StockCount.Cqrs;
|
||||
|
||||
public class GetStockCountListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public DateTime? CountDate { get; set; }
|
||||
public Data.Enums.StockCountStatus Status { get; set; }
|
||||
public string? WarehouseName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record GetStockCountListQuery() : IRequest<List<GetStockCountListResponse>>;
|
||||
|
||||
public class GetStockCountListHandler : IRequestHandler<GetStockCountListQuery, List<GetStockCountListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetStockCountListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetStockCountListResponse>> Handle(GetStockCountListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.StockCount
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Warehouse)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetStockCountListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
CountDate = x.CountDate,
|
||||
Status = x.Status,
|
||||
WarehouseName = x.Warehouse!.Name,
|
||||
Description = x.Description
|
||||
}).ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user