public async Task DeleteUserFromExternal(ExtUserSyncMessageDto extUserSync) { var existingUserEntity = await _unitOfWork.UserRepository.GetById(extUserSync.UserIdCurrent()); if (existingUserEntity == null) { _logger.LogError("Could not find user {@User}", extUserSync); } else { await _unitOfWork.UserRepository.Delete(existingUserEntity); } await _unitOfWork.SaveChanges(); _logger.LogInformation("deleted user {@User}", extUserSync); }
public async Task<UserReadDto> UpdateUserFromExternal(ExtUserSyncMessageDto extUserSync) { _logger.LogInformation("User with original id {OriginalId} before update = {@User}", extUserSync.UserIdCurrent(), extUserSync.UserProfileToSync); UserEntity userEntityToSave; var existingUserEntity = await _unitOfWork.UserRepository.GetById(extUserSync.UserIdCurrent()); if (existingUserEntity == null) { userEntityToSave = _mapper.Map<UserEntity>(extUserSync.UserProfileToSync); await _unitOfWork.UserRepository.Insert(userEntityToSave); } else { userEntityToSave = _mapper.Map(extUserSync.UserProfileToSync, existingUserEntity); await _unitOfWork.UserRepository.Update(userEntityToSave); } await _unitOfWork.SaveChanges(); var userReadDto = _mapper.Map<UserReadDto>(userEntityToSave); _logger.LogInformation("User with original id {OriginalId} after update = {@User}", extUserSync.UserIdCurrent(), userReadDto); return userReadDto; }