public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}")] HttpRequestMessage req, ILogger log, string customerId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetCustomerByIdHttpTriggerService getCustomerByIdService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("C# HTTP trigger function GetCustomerById processed a request. By Touchpoint " + touchpointId);

            if (!Guid.TryParse(customerId, out var customerGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(customerGuid));
            }

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            var customer = await getCustomerByIdService.GetCustomerAsync(customerGuid);

            return(customer == null?
                   HttpResponseMessageHelper.NoContent(customerGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(customer)));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", 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] IDeleteOutcomesHttpTriggerService outcomesDeleteService)
        {
            log.LogInformation("Delete Action Plan C# HTTP trigger function processed a request.");

            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));
            }

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(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 outcome = await outcomesDeleteService.GetOutcomeForCustomerAsync(customerGuid, interactionGuid, actionplanGuid, outcomesGuid);

            if (outcome == null)
            {
                return(HttpResponseMessageHelper.NoContent(outcomesGuid));
            }

            var outcomeDeleted = await outcomesDeleteService.DeleteAsync(outcome.OutcomeId.GetValueOrDefault());

            return(!outcomeDeleted?
                   HttpResponseMessageHelper.BadRequest(outcomesGuid) :
                       HttpResponseMessageHelper.Ok());
        }
示例#3
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "AdviserDetails/{adviserDetailId}")] HttpRequestMessage req, ILogger log, string adviserDetailId,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetAdviserDetailByIdHttpTriggerService getAdviserDetailByIdService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header.");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("Get Adviser Detail By Id C# HTTP trigger function  processed a request. " + touchpointId);

            if (!Guid.TryParse(adviserDetailId, out var adviserDetailGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(adviserDetailGuid));
            }

            var adviserDetail = await getAdviserDetailByIdService.GetAdviserDetailByIdAsync(adviserDetailGuid);

            return(adviserDetail == null
                ? HttpResponseMessageHelper.NoContent(adviserDetailGuid)
                : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(adviserDetail)));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/DiversityDetails")] HttpRequestMessage req, ILogger log, string customerId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetDiversityHttpTriggerService getDiversityService)
        {
            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));
            }

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            var diversityId = await getDiversityService.GetDiversityDetailIdAsync(customerGuid);

            return(diversityId == null?
                   HttpResponseMessageHelper.NoContent(customerGuid) :
                       HttpResponseMessageHelper.Ok(diversityId.Value));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/Interactions/{interactionId}/actionplans/{actionplanId}/Outcomes")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, string actionplanId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetOutcomesHttpTriggerService outcomesGetService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header.");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("Get Outcomes 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));
            }

            //Check customer
            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            //Check interactions
            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 outcomes = await outcomesGetService.GetOutcomesAsync(customerGuid);

            return(outcomes == null?
                   HttpResponseMessageHelper.NoContent(customerGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObjects(outcomes)));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers")] HttpRequestMessage req, ILogger log,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IGetCustomerHttpTriggerService getAllCustomerService)
        {
            var customer = await getAllCustomerService.GetAllCustomerAsync();

            return(customer == null?
                   HttpResponseMessageHelper.NoContent(Guid.NewGuid()) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(customer)));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/Interactions/{interactionId}/WebChats/{webChatId}")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, string webChatId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetWebChatByIdHttpTriggerService webChatGetService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'TouchpointId' in request header.");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("Get Web Chat By Id 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(webChatId, out var webChatGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(webChatGuid));
            }

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            var doesInteractionExist = resourceHelper.DoesInteractionResourceExistAndBelongToCustomer(interactionGuid, customerGuid);

            if (!doesInteractionExist)
            {
                return(HttpResponseMessageHelper.NoContent(interactionGuid));
            }

            var webChat = await webChatGetService.GetWebChatForCustomerAsync(customerGuid, interactionGuid, webChatGuid);

            return(webChat == null?
                   HttpResponseMessageHelper.NoContent(webChatGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(webChat)));
        }
        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)));
        }
示例#9
0
        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, "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, "get",
                                                                        Route = "CustomerSearch")] HttpRequestMessage req, ILogger log,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] ISearchCustomerHttpTriggerService searchCustomerService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("C# HTTP trigger function GetCustomerById processed a request. By Touchpoint " + touchpointId);

            SearchHelper.GetSearchServiceClient();
            var indexClient = SearchHelper.GetIndexClient();

            var query  = string.Empty;
            var filter = string.Empty;

            // Parse query parameter
            var givenName  = httpRequestMessageHelper.GetQueryNameValuePairs(req, "GivenName");
            var familyName = httpRequestMessageHelper.GetQueryNameValuePairs(req, "FamilyName");

            if (givenName != null && givenName.Length < 3)
            {
                log.LogWarning("Given Name must have a minimum of 3 characters");
                return(HttpResponseMessageHelper.NoContent());
            }

            if (!string.IsNullOrEmpty(givenName))
            {
                query += string.Format("GivenName:({0}* OR {0}) ", givenName.Trim());
            }

            if (familyName != null && familyName.Length < 3)
            {
                log.LogWarning("Family Name must have a minimum of 3 characters");
                return(HttpResponseMessageHelper.NoContent());
            }

            if (!string.IsNullOrEmpty(familyName))
            {
                query += string.Format("FamilyName:({0}* OR {0}) ", familyName.Trim());
            }

            var uniqueLearnerNumber = httpRequestMessageHelper.GetQueryNameValuePairs(req, "UniqueLearnerNumber");

            if (!string.IsNullOrEmpty(uniqueLearnerNumber))
            {
                query += string.Format("UniqueLearnerNumber:{0}", uniqueLearnerNumber.Trim());
            }

            var dob = httpRequestMessageHelper.GetQueryNameValuePairs(req, "DateofBirth");

            if (!string.IsNullOrEmpty(dob))
            {
                if (DateTime.TryParse(dob.Trim(), CultureInfo.CurrentCulture, DateTimeStyles.None, out var dateOfBirth))
                {
                    filter = string.Format("DateofBirth eq {0:yyyy-MM-dd}", dateOfBirth);
                }
                else
                {
                    return(HttpResponseMessageHelper.NoContent());
                }
            }

            if (string.IsNullOrWhiteSpace(query) && string.IsNullOrWhiteSpace(filter))
            {
                return(HttpResponseMessageHelper.NoContent());
            }

            log.LogInformation("Attempting to search customers");

            var customer = await searchCustomerService.SearchCustomerAsync(indexClient, query, filter);

            log.LogInformation("Search completed");

            return(customer == null?
                   HttpResponseMessageHelper.NoContent() :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObjects(customer)));
        }
示例#12
0
        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)));
        }
示例#15
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "AdviserDetails/{adviserDetailId}")] HttpRequestMessage req, ILogger log, string adviserDetailId,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IValidate validate,
                                                           [Inject] IPatchAdviserDetailHttpTriggerService adviserDetailsPatchService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'APIM-TouchpointId' in request header.");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("Patch Adviser Detail C# HTTP trigger function processed a request. " + touchpointId);

            if (!Guid.TryParse(adviserDetailId, out var adviserDetailGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(adviserDetailGuid));
            }

            Models.AdviserDetailPatch adviserDetailPatchRequest;

            try
            {
                adviserDetailPatchRequest = await httpRequestMessageHelper.GetAdviserDetailFromRequest <Models.AdviserDetailPatch>(req);
            }
            catch (JsonException ex)
            {
                return(HttpResponseMessageHelper.UnprocessableEntity(ex));
            }

            if (adviserDetailPatchRequest == null)
            {
                return(HttpResponseMessageHelper.UnprocessableEntity(req));
            }

            adviserDetailPatchRequest.LastModifiedTouchpointId = touchpointId;

            var errors = validate.ValidateResource(adviserDetailPatchRequest, false);

            if (errors != null && errors.Any())
            {
                return(HttpResponseMessageHelper.UnprocessableEntity(errors));
            }

            var adviserDetail = await adviserDetailsPatchService.GetAdviserDetailByIdAsync(adviserDetailGuid);

            if (adviserDetail == null)
            {
                return(HttpResponseMessageHelper.NoContent(adviserDetailGuid));
            }

            var patchedAdviserDetail = adviserDetailsPatchService.PatchResource(adviserDetail, adviserDetailPatchRequest);

            if (patchedAdviserDetail == null)
            {
                return(HttpResponseMessageHelper.NoContent(adviserDetailGuid));
            }

            var updatedAdviserDetail = await adviserDetailsPatchService.UpdateCosmosAsync(patchedAdviserDetail, adviserDetailGuid);

            return(updatedAdviserDetail == null
                ? HttpResponseMessageHelper.BadRequest(adviserDetailGuid)
                : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(updatedAdviserDetail)));
        }
        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> Run([HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "Customers/{customerId}/DiversityDetails/{diversityId}")] HttpRequestMessage req, ILogger log, string customerId, string diversityId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IValidate validate,
                                                           [Inject] IPatchDiversityHttpTriggerService patchDiversityService)
        {
            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 Patch Customer processed a request. By Touchpoint " + touchpointId);

            if (!Guid.TryParse(customerId, out var customerGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(customerGuid));
            }

            if (!Guid.TryParse(diversityId, out var diversityGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(diversityGuid));
            }

            Models.DiversityPatch diversityPatchRequest;

            try
            {
                diversityPatchRequest = await httpRequestMessageHelper.GetDiversityFromRequest <Models.DiversityPatch>(req);
            }
            catch (JsonException ex)
            {
                return(HttpResponseMessageHelper.UnprocessableEntity(ex));
            }

            if (diversityPatchRequest == null)
            {
                return(HttpResponseMessageHelper.UnprocessableEntity(req));
            }

            diversityPatchRequest.LastModifiedBy = touchpointId;

            // validate the request
            var errors = validate.ValidateResource(diversityPatchRequest);

            if (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 diversity = await patchDiversityService.GetDiversityByIdAsync(customerGuid, diversityGuid);

            if (diversity == null)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            var updatedDiversity = await patchDiversityService.UpdateDiversityAsync(diversity, diversityPatchRequest);

            return(updatedDiversity == null?
                   HttpResponseMessageHelper.BadRequest(customerGuid) :
                       HttpResponseMessageHelper.Ok());
        }