59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Thirdparty.Patient.Cqrs;
|
|
|
|
public class UpdatePatientContactRequest
|
|
{
|
|
public string? Id { 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 UpdatePatientContactResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public bool Success { get; set; }
|
|
}
|
|
|
|
public record UpdatePatientContactCommand(UpdatePatientContactRequest Data) : IRequest<UpdatePatientContactResponse>;
|
|
|
|
public class UpdatePatientContactHandler : IRequestHandler<UpdatePatientContactCommand, UpdatePatientContactResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public UpdatePatientContactHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<UpdatePatientContactResponse> Handle(UpdatePatientContactCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await _context.PatientContact
|
|
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
|
|
|
if (entity == null)
|
|
{
|
|
return new UpdatePatientContactResponse
|
|
{
|
|
Id = request.Data.Id,
|
|
Success = false
|
|
};
|
|
}
|
|
|
|
entity.Name = request.Data.Name;
|
|
entity.Title = request.Data.Title;
|
|
entity.PhoneNumber = request.Data.PhoneNumber;
|
|
entity.EmailAddress = request.Data.EmailAddress;
|
|
entity.Description = request.Data.Description;
|
|
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
|
|
return new UpdatePatientContactResponse
|
|
{
|
|
Id = entity.Id,
|
|
Success = true
|
|
};
|
|
}
|
|
} |