61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
|
|
namespace Indotalent.Features.Thirdparty.Patient.Cqrs;
|
|
|
|
public class CreatePatientContactRequest
|
|
{
|
|
public string? PatientId { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? Title { get; set; }
|
|
public string? PhoneNumber { get; set; }
|
|
public string? EmailAddress { get; set; }
|
|
public string? Description { get; set; }
|
|
}
|
|
|
|
public class CreatePatientContactResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Name { get; set; }
|
|
}
|
|
|
|
public record CreatePatientContactCommand(CreatePatientContactRequest Data) : IRequest<CreatePatientContactResponse>;
|
|
|
|
public class CreatePatientContactHandler : IRequestHandler<CreatePatientContactCommand, CreatePatientContactResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public CreatePatientContactHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<CreatePatientContactResponse> Handle(CreatePatientContactCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entityName = nameof(Data.Entities.PatientContact);
|
|
|
|
var autoNo = await _context.GenerateAutoNumberAsync(
|
|
entityName: entityName,
|
|
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
|
ct: cancellationToken
|
|
);
|
|
|
|
var entity = new Data.Entities.PatientContact
|
|
{
|
|
AutoNumber = autoNo,
|
|
PatientId = request.Data.PatientId,
|
|
Name = request.Data.Name,
|
|
Title = request.Data.Title,
|
|
PhoneNumber = request.Data.PhoneNumber,
|
|
EmailAddress = request.Data.EmailAddress,
|
|
Description = request.Data.Description
|
|
};
|
|
|
|
_context.PatientContact.Add(entity);
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
|
|
return new CreatePatientContactResponse
|
|
{
|
|
Id = entity.Id,
|
|
Name = entity.Name
|
|
};
|
|
}
|
|
} |