81 lines
3.2 KiB
C#
81 lines
3.2 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Setting.Company.Cqrs;
|
|
|
|
public class GetCompanyByIdResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? Description { get; set; }
|
|
public bool IsDefault { get; set; }
|
|
public string? CurrencyId { get; set; }
|
|
public string? TaxIdentification { get; set; }
|
|
public string? BusinessLicense { get; set; }
|
|
public string? CompanyLogo { get; set; }
|
|
public string? StreetAddress { get; set; }
|
|
public string? City { get; set; }
|
|
public string? StateProvince { get; set; }
|
|
public string? ZipCode { get; set; }
|
|
public string? Phone { get; set; }
|
|
public string? Email { get; set; }
|
|
public string? SocialMediaLinkedIn { get; set; }
|
|
public string? SocialMediaX { get; set; }
|
|
public string? SocialMediaFacebook { get; set; }
|
|
public string? SocialMediaInstagram { get; set; }
|
|
public string? SocialMediaTikTok { 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 GetCompanyByIdQuery(string Id) : IRequest<GetCompanyByIdResponse?>;
|
|
|
|
public class GetCompanyByIdHandler : IRequestHandler<GetCompanyByIdQuery, GetCompanyByIdResponse?>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetCompanyByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<GetCompanyByIdResponse?> Handle(GetCompanyByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Company
|
|
.AsNoTracking()
|
|
.Where(x => x.Id == request.Id)
|
|
.Select(x => new GetCompanyByIdResponse
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
Description = x.Description,
|
|
IsDefault = x.IsDefault,
|
|
CurrencyId = x.CurrencyId,
|
|
TaxIdentification = x.TaxIdentification,
|
|
BusinessLicense = x.BusinessLicense,
|
|
CompanyLogo = x.CompanyLogo,
|
|
StreetAddress = x.StreetAddress,
|
|
City = x.City,
|
|
StateProvince = x.StateProvince,
|
|
ZipCode = x.ZipCode,
|
|
Phone = x.Phone,
|
|
Email = x.Email,
|
|
SocialMediaLinkedIn = x.SocialMediaLinkedIn,
|
|
SocialMediaX = x.SocialMediaX,
|
|
SocialMediaFacebook = x.SocialMediaFacebook,
|
|
SocialMediaInstagram = x.SocialMediaInstagram,
|
|
SocialMediaTikTok = x.SocialMediaTikTok,
|
|
OtherInformation1 = x.OtherInformation1,
|
|
OtherInformation2 = x.OtherInformation2,
|
|
OtherInformation3 = x.OtherInformation3,
|
|
CreatedAt = x.CreatedAt,
|
|
CreatedBy = x.CreatedBy,
|
|
UpdatedAt = x.UpdatedAt,
|
|
UpdatedBy = x.UpdatedBy
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
} |