public async Task <string> Handle(CreateEpaOrganisationContactRequest request, CancellationToken cancellationToken) { ProcessRequestFieldsForSpecialCharacters(request); var validationResponse = _validator.ValidatorCreateEpaOrganisationContactRequest(request); if (!validationResponse.IsValid) { var message = validationResponse.Errors.Aggregate(string.Empty, (current, error) => current + error.ErrorMessage + "; "); _logger.LogError(message); if (validationResponse.Errors.Any(x => x.StatusCode == ValidationStatusCode.BadRequest.ToString())) { throw new BadRequestException(message); } if (validationResponse.Errors.Any(x => x.StatusCode == ValidationStatusCode.AlreadyExists.ToString())) { throw new AlreadyExistsException(message); } throw new Exception(message); } var newUsername = _organisationIdGenerator.GetNextContactUsername(); if (newUsername == string.Empty) { throw new Exception("A valid contact user name could not be generated"); } var contact = MapOrganisationContactRequestToContact(request, newUsername); return(await _registerRepository.CreateEpaOrganisationContact(contact)); }
public async Task <ValidationResponse> Handle(CreateEpaContactValidationRequest request, CancellationToken cancellationToken) { var result = _validator.ValidatorCreateEpaOrganisationContactRequest(new CreateEpaOrganisationContactRequest { EndPointAssessorOrganisationId = request.OrganisationId, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, PhoneNumber = request.Phone }); return(await Task.FromResult(result)); }