namespace DocuMed.Repository.Handlers.Hospitals; public class UpdateHospitalCommandHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler { public async Task Handle(UpdateHospitalCommand request, CancellationToken cancellationToken) { var ent = await repositoryWrapper.SetRepository().TableNoTracking .FirstOrDefaultAsync(h => h.Id == request.Id, cancellationToken); if (ent == null) throw new BaseApiException(ApiResultStatusCode.NotFound, "Hospital not found"); var newEnt = Hospital.Create(request.Name, request.Detail, request.Address, request.UniversityId); newEnt.Id = ent.Id; newEnt.CreatedAt = ent.CreatedAt; newEnt.CreatedBy = ent.CreatedBy; repositoryWrapper.SetRepository().Update(newEnt); await repositoryWrapper.SaveChangesAsync(cancellationToken); return newEnt.Id; } }