initial commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
namespace Indotalent.Features.Sales.SalesOrder.Cqrs;
|
||||
|
||||
public class SalesOrderLookupResponse
|
||||
{
|
||||
public List<LookupItem> Customers { get; set; } = new();
|
||||
public List<LookupItem> Employees { get; set; } = new();
|
||||
public List<LookupItem> Taxes { get; set; } = new();
|
||||
public List<LookupItem> Products { get; set; } = new();
|
||||
public List<LookupItem> SalesOrderGroups { get; set; } = new();
|
||||
public List<LookupItem> SalesOrderCategories { 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 GetSalesOrderLookupQuery() : IRequest<SalesOrderLookupResponse>;
|
||||
|
||||
public class GetSalesOrderLookupHandler : IRequestHandler<GetSalesOrderLookupQuery, SalesOrderLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetSalesOrderLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<SalesOrderLookupResponse> Handle(GetSalesOrderLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new SalesOrderLookupResponse();
|
||||
|
||||
response.Customers = await _context.Patient.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Employees = await _context.Employee.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Taxes = await _context.Tax.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Products = await _context.Product.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.SalesOrderGroups = await _context.SalesOrderGroup.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.SalesOrderCategories = await _context.SalesOrderCategory.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(SalesOrderStatus))
|
||||
.Cast<SalesOrderStatus>()
|
||||
.Select(x => new LookupStatusItem
|
||||
{
|
||||
Value = (int)x,
|
||||
Name = x.GetDescription()
|
||||
}).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user