55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Organization.Designation.Cqrs;
|
|
|
|
public class GetDesignationByIdResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? AutoNumber { get; set; }
|
|
public string? Code { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? Description { get; set; }
|
|
public string? Level { get; set; }
|
|
public string? OtherInformation1 { get; set; }
|
|
public string? OtherInformation2 { get; set; }
|
|
public string? OtherInformation3 { get; set; }
|
|
public DateTimeOffset? CreatedAt { get; set; }
|
|
public string? CreatedBy { get; set; }
|
|
public DateTimeOffset? UpdatedAt { get; set; }
|
|
public string? UpdatedBy { get; set; }
|
|
}
|
|
|
|
public record GetDesignationByIdQuery(string Id) : IRequest<GetDesignationByIdResponse?>;
|
|
|
|
public class GetDesignationByIdHandler : IRequestHandler<GetDesignationByIdQuery, GetDesignationByIdResponse?>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetDesignationByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<GetDesignationByIdResponse?> Handle(GetDesignationByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Designation
|
|
.AsNoTracking()
|
|
.Where(x => x.Id == request.Id)
|
|
.Select(x => new GetDesignationByIdResponse
|
|
{
|
|
Id = x.Id,
|
|
AutoNumber = x.AutoNumber,
|
|
Code = x.Code,
|
|
Name = x.Name,
|
|
Description = x.Description,
|
|
Level = x.Level,
|
|
OtherInformation1 = x.OtherInformation1,
|
|
OtherInformation2 = x.OtherInformation2,
|
|
OtherInformation3 = x.OtherInformation3,
|
|
CreatedAt = x.CreatedAt,
|
|
CreatedBy = x.CreatedBy,
|
|
UpdatedAt = x.UpdatedAt,
|
|
UpdatedBy = x.UpdatedBy
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
} |