public async Task <IActionResult> Post([FromBody] AccessProtectionMarkingsRequest accessProtectionMarkingsRequest) { _logger.LogDebug(JsonConvert.SerializeObject(accessProtectionMarkingsRequest)); if (!ModelState.IsValid) { return(BadRequest()); } try { var result = await _accessProtectionService.CreateCase(accessProtectionMarkingsRequest); _logger.LogWarning($"Case result: { result }"); return(Ok(result)); } catch (Exception ex) { _logger.LogWarning($"HomeContoller:Post, Case an exception has occurred while calling CreateCase, ex: {ex}"); return(StatusCode(500)); } }
public async Task <string> CreateCase(AccessProtectionMarkingsRequest accessProtectionMarkingsRequest) { var description = $@"FirstName: {accessProtectionMarkingsRequest.FirstName} LastName: { accessProtectionMarkingsRequest.LastName} Email: {accessProtectionMarkingsRequest.Email} Phone: {accessProtectionMarkingsRequest.Phone} FurtherLlocationDetails: {accessProtectionMarkingsRequest.FurtherLocationDetails}"; if (accessProtectionMarkingsRequest.CustomersAddress != null) { description += $@"AddressLine1: {accessProtectionMarkingsRequest.CustomersAddress.AddressLine1} AddressLine2: {accessProtectionMarkingsRequest.CustomersAddress.AddressLine2} Town: {accessProtectionMarkingsRequest.CustomersAddress.Town} Postcode: {accessProtectionMarkingsRequest.CustomersAddress.Postcode} SelectedAddress: {accessProtectionMarkingsRequest.CustomersAddress.SelectedAddress} "; } var crmCase = new Case { EventCode = 4000031, EventTitle = "Basic Verint Case", Description = description, Street = new Street { Reference = accessProtectionMarkingsRequest.StreetAddress.PlaceRef } }; if (!string.IsNullOrEmpty(accessProtectionMarkingsRequest.FirstName) && !string.IsNullOrEmpty(accessProtectionMarkingsRequest.LastName)) { crmCase.Customer = new Customer { Forename = accessProtectionMarkingsRequest.FirstName, Surname = accessProtectionMarkingsRequest.LastName }; if (!string.IsNullOrEmpty(accessProtectionMarkingsRequest.Email)) { crmCase.Customer.Email = accessProtectionMarkingsRequest.Email; } if (!string.IsNullOrEmpty(accessProtectionMarkingsRequest.Phone)) { crmCase.Customer.Telephone = accessProtectionMarkingsRequest.Phone; } if (string.IsNullOrEmpty(accessProtectionMarkingsRequest.CustomersAddress.PlaceRef)) { crmCase.Customer.Address = new Address { AddressLine1 = accessProtectionMarkingsRequest.CustomersAddress.AddressLine1, AddressLine2 = accessProtectionMarkingsRequest.CustomersAddress.AddressLine2, AddressLine3 = accessProtectionMarkingsRequest.CustomersAddress.Town, Postcode = accessProtectionMarkingsRequest.CustomersAddress.Postcode, }; } else { crmCase.Customer.Address = new Address { Reference = accessProtectionMarkingsRequest.CustomersAddress.PlaceRef, UPRN = accessProtectionMarkingsRequest.CustomersAddress.PlaceRef }; } } try { var response = await _VerintServiceGateway.CreateCase(crmCase); if (!response.IsSuccessStatusCode) { throw new Exception($"AccessProtectionService CreateCase VerintServiceGateway responded with status code {response.StatusCode}"); } return(response.ResponseContent); } catch (Exception ex) { throw new Exception($"AccessProtectionService CreateCase an exception has occured while creating the case in verint service", ex); } }