public async Task <IActionResult> Post([FromBody] AbandonedVehicleReport abandonedVehicleReport)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid request parameters.");
            }

            return(Ok(await _abandonedVehicleService.CreateCase(abandonedVehicleReport)));
        }
        public async Task <string> CreateCase(AbandonedVehicleReport abandonedVehicleReport)
        {
            var crmCase = abandonedVehicleReport
                          .ToCase(_VOFConfiguration, _verintOptions);

            var streetResult = await _verintServiceGateway.GetStreet(abandonedVehicleReport.StreetAddress.PlaceRef);

            if (!streetResult.IsSuccessStatusCode)
            {
                throw new Exception("AbandonedVehicleService.CreateCase: GetStreet status code not successful");
            }

            // confirm uses the USRN for the street
            // however Verint uses the verint-address-id (Reference) (abandonedVehicleReport.StreetAddress.PlaceRef) for street
            crmCase.Street.USRN = streetResult.ResponseContent.USRN;

            try
            {
                var response = await _verintServiceGateway.CreateVerintOnlineFormCase(crmCase.ToConfirmIntegrationFormCase(_VOFConfiguration));

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception("AbandonedVehicleService.CreateCase: CreateVerintOnlineFormCase status code not successful");
                }

                var person = new Person
                {
                    FirstName = abandonedVehicleReport.FirstName,
                    LastName  = abandonedVehicleReport.LastName,
                    Email     = abandonedVehicleReport.Email,
                    Phone     = abandonedVehicleReport.Phone
                };

                _mailHelper.SendEmail(
                    person,
                    EMailTemplate.AbandonedVehicleReport,
                    response.ResponseContent.VerintCaseReference,
                    abandonedVehicleReport.StreetAddress);

                return(response.ResponseContent.VerintCaseReference);
            }
            catch (Exception ex)
            {
                throw new Exception($"AbandonedVehicleService.CreateCase: CRMService CreateAbandonedVehicleService an exception has occured while creating the case in verint service", ex);
            }
        }
Пример #3
0
        public static Case ToCase(this AbandonedVehicleReport model,
                                  ConfirmIntegrationFormOptions _VOFConfiguration,
                                  VerintOptions _verintOptions)
        {
            var crmCase = new Case
            {
                EventCode                  = _VOFConfiguration.EventId,
                EventTitle                 = _verintOptions.EventTitle,
                Classification             = _verintOptions.Classification,
                RaisedByBehaviour          = RaisedByBehaviourEnum.Individual,
                FurtherLocationInformation = model.FurtherDetails,
                Description                = GenerateDescription(model),
                Customer = new Customer
                {
                    Forename  = model.FirstName,
                    Surname   = model.LastName,
                    Email     = model.Email,
                    Telephone = model.Phone,
                    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.StreetAddress?.PlaceRef))
            {
                crmCase.AssociatedWithBehaviour = AssociatedWithBehaviourEnum.Street;
                crmCase.Street = new Street
                {
                    Reference   = model.StreetAddress.PlaceRef,
                    Description = model.StreetAddress.ToString()
                };
            }

            return(crmCase);
        }
Пример #4
0
        private static string GenerateDescription(AbandonedVehicleReport abandonedVehicleReport)
        {
            StringBuilder description = new StringBuilder();

            if (!string.IsNullOrEmpty(abandonedVehicleReport.AbandonedReason))
            {
                description.Append($"Abandoned Reason: {abandonedVehicleReport.AbandonedReason}{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(abandonedVehicleReport.ImageOrVideo))
            {
                description.Append($"Photos Available: {abandonedVehicleReport.ImageOrVideo}{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(abandonedVehicleReport.VehicleMake))
            {
                description.Append($"Vehicle Make: {abandonedVehicleReport.VehicleMake}{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(abandonedVehicleReport.VehicleModel))
            {
                description.Append($"Vehicle Model: {abandonedVehicleReport.VehicleModel}{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(abandonedVehicleReport.VehicleColour))
            {
                description.Append($"Vehicle Colour: {abandonedVehicleReport.VehicleColour}{Environment.NewLine}");
            }

            if (!string.IsNullOrEmpty(abandonedVehicleReport.VehicleRegistration))
            {
                description.Append($"Vehicle Registration: {abandonedVehicleReport.VehicleRegistration}{Environment.NewLine}");
            }

            return(description.ToString());
        }