public void Setup() { _address = Substitute.For <Models.Address>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/Addressess/") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _validate = Substitute.For <IValidate>(); _postAddressHttpTriggerService = Substitute.For <IPostAddressHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }
public void Setup() { _session = Substitute.For <Models.Session>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Interactions/aa57e39e-4469-4c79-a9e9-9cb4ef410382/" + $"Sessions") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _validate = Substitute.For <IValidate>(); _postSessionHttpTriggerService = Substitute.For <IPostSessionHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }
public void Setup() { _session = Substitute.For <Session>(); _sessionPatch = Substitute.For <SessionPatch>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Sessions/1e1a555c-9633-4e12-ab28-09ed60d51cb3") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _validate = Substitute.For <IValidate>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _patchSessionHttpTriggerService = Substitute.For <IPatchSessionHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }
public void Setup() { _goal = Substitute.For <Models.Goal>(); _goalPatch = Substitute.For <GoalPatch>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Interactions/aa57e39e-4469-4c79-a9e9-9cb4ef410382/" + $"ActionPlans/d5369b9a-6959-4bd3-92fc-1583e72b7e51/" + $"Goals/d5369b9a-6959-4bd3-92fc-1583e72b7e51") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _validate = Substitute.For <IValidate>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _patchGoalHttpTriggerService = Substitute.For <IPatchGoalHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }
public void Setup() { _action = Substitute.For <Models.Action>(); _actionPatch = Substitute.For <ActionPatch>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Interactions/1e1a555c-9633-4e12-ab28-09ed60d51cb3" + $"ActionPlans/d5369b9a-6959-4bd3-92fc-1583e72b7e51" + $"Actions/233d861d-05ca-496e-aee1-6bd47ac13cb2") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _validate = Substitute.For <IValidate>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _patchActionHttpTriggerService = Substitute.For <IPatchActionHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); _patchActionHttpTriggerService.PatchResource(Arg.Any <string>(), _actionPatch).Returns(_action.ToString()); }
public static async Task <HttpResponseMessage> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "customers/{customerId}/ContactDetails/{contactid}")] HttpRequestMessage req, ILogger log, string customerId, string contactid, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPatchContactDetailsHttpTriggerService contactdetailsPatchService, [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 Patch Contact processed a request. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } if (!Guid.TryParse(contactid, out var contactGuid)) { return(HttpResponseMessageHelper.BadRequest(contactGuid)); } ContactDetailsPatch contactdetailsPatchRequest; try { contactdetailsPatchRequest = await httpRequestMessageHelper.GetContactDetailsFromRequest <ContactDetailsPatch>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (contactdetailsPatchRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } contactdetailsPatchRequest.LastModifiedTouchpointId = touchpointId; 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 contactdetails = await contactdetailsPatchService.GetContactDetailsForCustomerAsync(customerGuid, contactGuid); if (contactdetails == null) { return(HttpResponseMessageHelper.NoContent(contactGuid)); } var errors = validate.ValidateResource(contactdetailsPatchRequest, contactdetails, false); if (!string.IsNullOrEmpty(contactdetailsPatchRequest.EmailAddress)) { var contacts = await provider.GetContactsByEmail(contactdetailsPatchRequest.EmailAddress); if (contacts != null) { foreach (var contact in contacts) { var isReadOnly = await provider.DoesCustomerHaveATerminationDate(contact.CustomerId.GetValueOrDefault()); if (!isReadOnly && contact.CustomerId != contactdetails.CustomerId) { //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()); } } } } // Set Digital account properties so that contentenhancer can queue change on digital identity topic. var diaccount = await provider.GetIdentityForCustomerAsync(contactdetails.CustomerId.Value); if (diaccount != null) { if (contactdetailsPatchRequest.EmailAddress == string.Empty) { if (errors == null) { errors = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); } errors.Add(new System.ComponentModel.DataAnnotations.ValidationResult("Email Address cannot be removed because it is associated with a Digital Account", new List <string>() { "EmailAddress" })); return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } if (!string.IsNullOrEmpty(contactdetails.EmailAddress) && !string.IsNullOrEmpty(contactdetailsPatchRequest.EmailAddress) && contactdetails.EmailAddress?.ToLower() != contactdetailsPatchRequest.EmailAddress?.ToLower() && diaccount.IdentityStoreId.HasValue) { contactdetails.SetDigitalAccountEmailChanged(contactdetailsPatchRequest.EmailAddress?.ToLower(), diaccount.IdentityStoreId.Value); } } if (errors != null && errors.Any()) { return(HttpResponseMessageHelper.UnprocessableEntity(errors)); } var updatedContactDetails = await contactdetailsPatchService.UpdateAsync(contactdetails, contactdetailsPatchRequest); if (updatedContactDetails != null) { await contactdetailsPatchService.SendToServiceBusQueueAsync(updatedContactDetails, customerGuid, ApimURL); } return(updatedContactDetails == null? HttpResponseMessageHelper.BadRequest(contactGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(updatedContactDetails))); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "Customers/{customerId}/Addresses/{addressId}")] HttpRequestMessage req, ILogger log, string customerId, string addressId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPatchAddressHttpTriggerService addressPatchService) { 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("Patch Address C# HTTP trigger function processed a request. By Touchpoint " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } if (!Guid.TryParse(addressId, out var addressGuid)) { return(HttpResponseMessageHelper.BadRequest(addressGuid)); } AddressPatch addressPatchRequest; try { addressPatchRequest = await httpRequestMessageHelper.GetAddressFromRequest <AddressPatch>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (addressPatchRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } addressPatchRequest.LastModifiedTouchpointId = touchpointId; var errors = validate.ValidateResource(addressPatchRequest, false); 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 addressForCustomer = await addressPatchService.GetAddressForCustomerAsync(customerGuid, addressGuid); if (addressForCustomer == null) { return(HttpResponseMessageHelper.NoContent(addressGuid)); } var patchedAddress = addressPatchService.PatchResource(addressForCustomer, addressPatchRequest); if (patchedAddress == null) { return(HttpResponseMessageHelper.NoContent(addressGuid)); } var updatedAddress = await addressPatchService.UpdateCosmosAsync(patchedAddress, addressGuid); if (updatedAddress != null) { await addressPatchService.SendToServiceBusQueueAsync(updatedAddress, customerGuid, ApimURL); } return(updatedAddress == null? HttpResponseMessageHelper.BadRequest(addressGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(updatedAddress))); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "Customers/{customerId}/Interactions/{interactionId}/actionplans/{actionplanId}/Outcomes/{OutcomeId}")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, string actionplanId, string OutcomeId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPatchOutcomesHttpTriggerService outcomesPatchService) { 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("Patch Action Plan C# HTTP trigger function 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)); } if (!Guid.TryParse(actionplanId, out var actionplanGuid)) { return(HttpResponseMessageHelper.BadRequest(actionplanGuid)); } if (!Guid.TryParse(OutcomeId, out var outcomesGuid)) { return(HttpResponseMessageHelper.BadRequest(outcomesGuid)); } Models.OutcomesPatch outcomesPatchRequest; try { outcomesPatchRequest = await httpRequestMessageHelper.GetOutcomesFromRequest <Models.OutcomesPatch>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (outcomesPatchRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } outcomesPatchRequest.LastModifiedTouchpointId = touchpointId; var errors = validate.ValidateResource(outcomesPatchRequest); 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 doesActionPlanExist = resourceHelper.DoesActionPlanResourceExistAndBelongToCustomer(actionplanGuid, interactionGuid, customerGuid); if (!doesActionPlanExist) { return(HttpResponseMessageHelper.NoContent(actionplanGuid)); } var outcomeForCustomer = await outcomesPatchService.GetOutcomesForCustomerAsync(customerGuid, interactionGuid, actionplanGuid, outcomesGuid); if (outcomeForCustomer == null) { return(HttpResponseMessageHelper.NoContent(outcomesGuid)); } var patchedOutcome = outcomesPatchService.PatchResource(outcomeForCustomer, outcomesPatchRequest); if (patchedOutcome == null) { return(HttpResponseMessageHelper.NoContent(outcomesGuid)); } var updatedOutcomes = await outcomesPatchService.UpdateCosmosAsync(patchedOutcome, outcomesGuid); if (updatedOutcomes != null) { await outcomesPatchService.SendToServiceBusQueueAsync(updatedOutcomes, customerGuid, ApimURL); } return(updatedOutcomes == null? HttpResponseMessageHelper.BadRequest(outcomesGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(updatedOutcomes))); }
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, "patch", Route = "Customers/{customerId}/Interactions/{interactionId}/Transfers/{transferId}")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, string transferId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IValidate validate, [Inject] IPatchTransferHttpTriggerService transferPatchService) { 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("Patch Transfer C# HTTP trigger function processed a request. By Touchpoint. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } if (!Guid.TryParse(interactionId, out var interactionGuid)) { return(HttpResponseMessageHelper.BadRequest(interactionGuid)); } if (!Guid.TryParse(transferId, out var transferGuid)) { return(HttpResponseMessageHelper.BadRequest(transferGuid)); } Models.TransferPatch transferPatchRequest; try { transferPatchRequest = await httpRequestMessageHelper.GetTransferFromRequest <Models.TransferPatch>(req); } catch (JsonException ex) { return(HttpResponseMessageHelper.UnprocessableEntity(ex)); } if (transferPatchRequest == null) { return(HttpResponseMessageHelper.UnprocessableEntity(req)); } transferPatchRequest.LastModifiedTouchpointId = touchpointId; var errors = validate.ValidateResource(transferPatchRequest, false); 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 transfer = await transferPatchService.GetTransferForCustomerAsync(customerGuid, transferGuid); if (transfer == null) { return(HttpResponseMessageHelper.NoContent(transferGuid)); } var updatedTransfer = await transferPatchService.UpdateAsync(transfer, transferPatchRequest); if (updatedTransfer != null) { await transferPatchService.SendToServiceBusQueueAsync(transfer, customerGuid, ApimURL); } return(updatedTransfer == null? HttpResponseMessageHelper.BadRequest(transferGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(updatedTransfer))); }
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))); }