initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public class LookupResponse
|
||||
{
|
||||
public List<LookupItem> Branches { get; set; } = new();
|
||||
public List<LookupItem> Departments { get; set; } = new();
|
||||
public List<LookupItem> Designations { get; set; } = new();
|
||||
public List<LookupItem> Grades { get; set; } = new();
|
||||
public List<LookupItem> Incomes { get; set; } = new();
|
||||
public List<LookupItem> Deductions { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Code { get; set; }
|
||||
public decimal SalaryFrom { get; set; }
|
||||
public decimal SalaryTo { get; set; }
|
||||
}
|
||||
|
||||
public record LookupQuery() : IRequest<LookupResponse>;
|
||||
|
||||
public class LookupHandler : IRequestHandler<LookupQuery, LookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public LookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupResponse> Handle(LookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LookupResponse();
|
||||
|
||||
response.Branches = await _context.Branch
|
||||
.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Departments = await _context.Department
|
||||
.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.CostCenter })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Designations = await _context.Designation
|
||||
.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Grades = await _context.Grade
|
||||
.AsNoTracking()
|
||||
.Select(x => new LookupItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Code = x.Code,
|
||||
SalaryFrom = x.SalaryFrom,
|
||||
SalaryTo = x.SalaryTo
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Incomes = await _context.Income
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Status == "Active")
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Deductions = await _context.Deduction
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Status == "Active")
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user