public static async Task <HttpResponseMessage> Run3([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Anonymise/Prod-to-Pre")] HttpRequestMessage req, ILogger log, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IPostAnonymiseHttpTriggerService AnonymisePostService) { await AnonymisePostService.Anonymise(); return(HttpResponseMessageHelper.Created("Ok")); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "AdviserDetails")] HttpRequestMessage req, ILogger log, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostAdviserDetailHttpTriggerService adviserDetailsPostService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("Post Adviser Detail C# HTTP trigger function processed a request. " + touchpointId); Models.AdviserDetail adviserDetailRequest; try { adviserDetailRequest = await httpRequestMessageHelper.GetAdviserDetailFromRequest <Models.AdviserDetail>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (adviserDetailRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } adviserDetailRequest.LastModifiedTouchpointId = touchpointId; var errors = validate.ValidateResource(adviserDetailRequest, true); if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var adviserDetail = await adviserDetailsPostService.CreateAsync(adviserDetailRequest); return(adviserDetail == null ? HttpResponseMessageHelper.BadRequest() : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(adviserDetail))); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Customers/{customerId}/DiversityDetails")] HttpRequestMessage req, ILogger log, string customerId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostDiversityHttpTriggerService postDiversityService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function processed a request. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } Models.Diversity diversityRequest; try { diversityRequest = await httpRequestMessageHelper.GetDiversityFromRequest <Models.Diversity>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (diversityRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } diversityRequest.SetIds(customerGuid, touchpointId); var errors = validate.ValidateResource(diversityRequest); if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var isCustomerReadOnly = await resourceHelper.IsCustomerReadOnly(customerGuid); if (isCustomerReadOnly) { return(HttpResponseMessageHelper.Forbidden(customerGuid)); } var doesDiversityDetailsExist = postDiversityService.DoesDiversityDetailsExistForCustomer(customerGuid); if (doesDiversityDetailsExist) { return(HttpResponseMessageHelper.Conflict()); } var diversity = await postDiversityService.CreateAsync(diversityRequest); return(diversity == null ? HttpResponseMessageHelper.BadRequest(customerGuid) : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(diversity))); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "customers/{customerId}/interactions/{interactionId}/sessions/")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostSessionHttpTriggerService sessionPostService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } var ApimURL = httpRequestMessageHelper.GetApimURL(req); if (string.IsNullOrEmpty(ApimURL)) { log.LogInformation("Unable to locate 'apimurl' in request header"); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function Post Session processed a request. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } if (!Guid.TryParse(interactionId, out var interactionGuid)) { return(HttpResponseMessageHelper.BadRequest(interactionGuid)); } Session sessionRequest; try { sessionRequest = await httpRequestMessageHelper.GetSessionFromRequest <Session>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (sessionRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } sessionRequest.SetIds(customerGuid, interactionGuid, touchpointId); var errors = validate.ValidateResource(sessionRequest); if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var isCustomerReadOnly = await resourceHelper.IsCustomerReadOnly(customerGuid); if (isCustomerReadOnly) { return(HttpResponseMessageHelper.Forbidden(customerGuid)); } var doesInteractionExist = resourceHelper.DoesInteractionResourceExistAndBelongToCustomer(interactionGuid, customerGuid); if (!doesInteractionExist) { return(HttpResponseMessageHelper.NoContent(interactionGuid)); } var session = await sessionPostService.CreateAsync(sessionRequest); if (session != null) { await sessionPostService.SendToServiceBusQueueAsync(session, ApimURL); } return(session == null ? HttpResponseMessageHelper.BadRequest(customerGuid) : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(session))); }
public static async Task <HttpResponseMessage> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "customers/{customerId}/ContactDetails/")] HttpRequestMessage req, ILogger log, string customerId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostContactDetailsHttpTriggerService contactdetailsPostService, [Inject] IDocumentDBProvider provider) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } var ApimURL = httpRequestMessageHelper.GetApimURL(req); if (string.IsNullOrEmpty(ApimURL)) { log.LogInformation("Unable to locate 'apimurl' in request header"); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function Post Contact processed a request. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } Models.ContactDetails contactdetailsRequest; try { contactdetailsRequest = await httpRequestMessageHelper.GetContactDetailsFromRequest <Contact.Models.ContactDetails>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (contactdetailsRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } contactdetailsRequest.SetIds(customerGuid, touchpointId); var errors = validate.ValidateResource(contactdetailsRequest, null, true); if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var isCustomerReadOnly = await resourceHelper.IsCustomerReadOnly(customerGuid); if (isCustomerReadOnly) { return(HttpResponseMessageHelper.Forbidden(customerGuid)); } var doesContactDetailsExist = contactdetailsPostService.DoesContactDetailsExistForCustomer(customerGuid); if (doesContactDetailsExist) { return(HttpResponseMessageHelper.Conflict()); } if (!string.IsNullOrEmpty(contactdetailsRequest.EmailAddress)) { var contacts = await provider.GetContactsByEmail(contactdetailsRequest.EmailAddress); if (contacts != null) { foreach (var contact in contacts) { var isReadOnly = await provider.DoesCustomerHaveATerminationDate(contact.CustomerId.GetValueOrDefault()); if (!isReadOnly) { //if a customer that has the same email address is not readonly (has date of termination) //then email address on the request cannot be used. return(HttpResponseMessageHelper.Conflict()); } } } } var contactDetails = await contactdetailsPostService.CreateAsync(contactdetailsRequest); if (contactDetails != null) { await contactdetailsPostService.SendToServiceBusQueueAsync(contactDetails, ApimURL); } return(contactDetails == null ? HttpResponseMessageHelper.BadRequest(customerGuid) : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(contactDetails))); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Customers/{customerId}/Addresses")] HttpRequestMessage req, ILogger log, string customerId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostAddressHttpTriggerService addressPostService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header"); return(HttpResponseMessageHelper.BadRequest()); } var ApimURL = httpRequestMessageHelper.GetApimURL(req); if (string.IsNullOrEmpty(ApimURL)) { log.LogInformation("Unable to locate 'apimurl' in request header"); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("Post Address C# HTTP trigger function processed a request. By Touchpoint " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } Models.Address addressRequest; try { addressRequest = await httpRequestMessageHelper.GetAddressFromRequest <Models.Address>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (addressRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } addressRequest.SetIds(customerGuid, touchpointId); var errors = validate.ValidateResource(addressRequest, true); if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var isCustomerReadOnly = await resourceHelper.IsCustomerReadOnly(customerGuid); if (isCustomerReadOnly) { return(HttpResponseMessageHelper.Forbidden(customerGuid)); } var address = await addressPostService.CreateAsync(addressRequest); if (address != null) { await addressPostService.SendToServiceBusQueueAsync(address, ApimURL); } return(address == null ? HttpResponseMessageHelper.BadRequest(customerGuid) : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(address))); }
public static async Task <HttpResponseMessage> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Customers/")] HttpRequestMessage req, ILogger log, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPostCustomerHttpTriggerService customerPostService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header"); return(HttpResponseMessageHelper.BadRequest()); } var ApimURL = httpRequestMessageHelper.GetApimURL(req); if (string.IsNullOrEmpty(ApimURL)) { log.LogInformation("Unable to locate 'apimurl' in request header"); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function Post Customer processed a request. By Touchpoint " + touchpointId); Models.Customer customerRequest; try { customerRequest = await httpRequestMessageHelper.GetCustomerFromRequest <Models.Customer>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (customerRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } customerRequest.LastModifiedTouchpointId = touchpointId; var errors = validate.ValidateResource(customerRequest, true); if (errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var customer = await customerPostService.CreateNewCustomerAsync(customerRequest); log.LogInformation("Apimurl: " + ApimURL); if (customer != null) { await customerPostService.SendToServiceBusQueueAsync(customer, ApimURL.ToString()); } return(customer == null ? HttpResponseMessageHelper.BadRequest() : HttpResponseMessageHelper.Created(JsonHelper.SerializeObject(customer))); }