61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Indotalent.Data.Enums;
|
|
using Indotalent.ConfigBackEnd.Extensions;
|
|
|
|
namespace Indotalent.Features.Inventory.NegativeAdjustment.Cqrs;
|
|
|
|
public class NegativeAdjustmentLookupResponse
|
|
{
|
|
public List<LookupItem> Warehouses { get; set; } = new();
|
|
public List<LookupItem> Products { get; set; } = new();
|
|
public List<LookupStatusItem> Statuses { get; set; } = new();
|
|
}
|
|
|
|
public class LookupItem
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Name { get; set; }
|
|
}
|
|
|
|
public class LookupStatusItem
|
|
{
|
|
public int Value { get; set; }
|
|
public string? Name { get; set; }
|
|
}
|
|
|
|
public record GetNegativeAdjustmentLookupQuery() : IRequest<NegativeAdjustmentLookupResponse>;
|
|
|
|
public class GetNegativeAdjustmentLookupHandler : IRequestHandler<GetNegativeAdjustmentLookupQuery, NegativeAdjustmentLookupResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
public GetNegativeAdjustmentLookupHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<NegativeAdjustmentLookupResponse> Handle(GetNegativeAdjustmentLookupQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var response = new NegativeAdjustmentLookupResponse();
|
|
|
|
response.Warehouses = await _context.Warehouse.AsNoTracking()
|
|
.Where(x => x.SystemWarehouse == false)
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
|
.ToListAsync(cancellationToken);
|
|
|
|
response.Products = await _context.Product.AsNoTracking()
|
|
.Where(x => x.Physical == true)
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
|
.ToListAsync(cancellationToken);
|
|
|
|
response.Statuses = Enum.GetValues(typeof(AdjustmentStatus))
|
|
.Cast<AdjustmentStatus>()
|
|
.Select(x => new LookupStatusItem
|
|
{
|
|
Value = (int)x,
|
|
Name = x.GetDescription()
|
|
}).ToList();
|
|
|
|
return response;
|
|
}
|
|
} |