public async Task <IActionResult> Post([FromBody] DroppedKerbRequest droppedKerbRequest) { if (!ModelState.IsValid) { throw new ArgumentException("Invalid request parameters."); } //return Ok(); return(Ok(await _droppedKerbService.CreateCase(droppedKerbRequest))); }
public async Task <string> CreateCase(DroppedKerbRequest kerbRequest) { var crmCase = kerbRequest .ToCase(_VOFConfiguration, _verintOptions); var streetResult = await _verintServiceGateway.GetStreet(kerbRequest.StreetAddressDroppedKerb.PlaceRef); if (!streetResult.IsSuccessStatusCode) { throw new Exception("DroppedKerbService.CreateCase: GetStreet status code not successful"); } // confirm uses the USRN for the street, // however Verint uses the verint-address-id (Reference) (kerbRequest.StreetAddress.PlaceRef) for streets crmCase.Street.USRN = streetResult.ResponseContent.USRN; try { var response = await _verintServiceGateway.CreateVerintOnlineFormCase(crmCase.ToConfirmIntegrationFormCase(_VOFConfiguration)); if (!response.IsSuccessStatusCode) { throw new Exception("DroppedKerbService.CreateCase: CreateVerintOnlineFormCase status code not successful"); } var person = new Person { FirstName = kerbRequest.FirstName, LastName = kerbRequest.LastName, Email = crmCase.Customer.Email, Phone = crmCase.Customer.Telephone }; if (!string.IsNullOrEmpty(person.Email)) { _mailHelper.SendEmail( person, EMailTemplate.StreetReport, response.ResponseContent.VerintCaseReference, kerbRequest.StreetAddressDroppedKerb); } return(response.ResponseContent.VerintCaseReference); } catch (Exception ex) { throw new Exception($"DroppedKerbService.CreateCase: CRMService CreateDroppedKerbService an exception has occured while creating the case in verint service", ex); } }
private static string GenerateDescription(DroppedKerbRequest kerbRequest) { StringBuilder description = new StringBuilder(); if (!string.IsNullOrEmpty(kerbRequest.PlanningReference) && kerbRequest.PlanningPermission == "Yes") { description.Append($"Planning application reference number: DC/{kerbRequest.PlanningReference}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.DischargeReference)) { description.Append($"Discharge of Conditions reference number: DC/{kerbRequest.DischargeReference}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.AccessFor)) { description.Append($"Access for: {kerbRequest.AccessFor}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.KerbLocation)) { description.Append($"Location of dropped kerb: {kerbRequest.KerbLocation}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.KerbLocationOther)) { description.Append($"Other: {kerbRequest.KerbLocationOther}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.PropertyOwner)) { description.Append($"Does the customer own the property?: {kerbRequest.PropertyOwner}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.RedundantAccessDetails)) { description.Append($"Redundant access details: {kerbRequest.RedundantAccessDetails}{Environment.NewLine}"); } if (!string.IsNullOrEmpty(kerbRequest.ContactPreference)) { description.Append($"Contact preference: {kerbRequest.ContactPreference}{Environment.NewLine}"); } return(description.ToString()); }
public static Case ToCase(this DroppedKerbRequest model, ConfirmIntegrationFormOptions _VOFConfiguration, VerintOptions _verintOptions) { var crmCase = new Case { EventCode = _VOFConfiguration.EventId, EventTitle = _verintOptions.EventTitle, Classification = _verintOptions.Classification, RaisedByBehaviour = RaisedByBehaviourEnum.Individual, FurtherLocationInformation = model.FurtherLocationDetails, Description = GenerateDescription(model), Customer = new Customer { Forename = model.FirstName, Surname = model.LastName, Email = model.ContactPreference == "Email" ? model.Email : model.EmailOptional, Telephone = model.ContactPreference == "Phone" ? model.Phone : model.PhoneOptional, Address = new Address { AddressLine1 = model.CustomersAddress.AddressLine1, AddressLine2 = model.CustomersAddress.AddressLine2, City = model.CustomersAddress.Town, Postcode = model.CustomersAddress.Postcode, UPRN = model.CustomersAddress.PlaceRef, Description = model.CustomersAddress.ToString() } } }; if (!string.IsNullOrWhiteSpace(model.StreetAddressDroppedKerb?.PlaceRef)) { crmCase.AssociatedWithBehaviour = AssociatedWithBehaviourEnum.Street; crmCase.Street = new Street { Reference = model.StreetAddressDroppedKerb.PlaceRef, Description = model.StreetAddressDroppedKerb.ToString() }; } return(crmCase); }