示例#1
0
        public void Calculate_ShouldReturnCalculatedCost(string haveLesiureKey, string haveBlueBadge, string calculatedCost)
        {
            // Arrange
            ParkingPermitsRequest request = new ParkingPermitsRequest
            {
                HaveLeisureKey = haveLesiureKey,
                HaveBlueBadge  = haveBlueBadge
            };

            // Act
            var response = _controller.Calculate(request);

            // Assert
            var result = Assert.IsType <ActionResult <string> >(response);

            Assert.Equal(calculatedCost, result.Value);
        }
示例#2
0
        public void SendParkingPermitEmail_ShouldMatchSubject()
        {
            //Arrange
            var callback = new Mail();
            var model    = new ParkingPermitsRequest();

            _mockGateway.Setup(_ => _.Send(It.IsAny <Mail>()))
            .Callback <Mail>((a) => callback = a);

            //Act
            _helper.SendParkingPermitEmail(EMailTemplate.GenericHtmlReport, "123", model);

            //Assert
            var callbackModel = JsonConvert.DeserializeObject <GenericReportMailModel>(callback.Payload);

            Assert.Equal("Your parking permit application", callbackModel.Subject);
        }
        public bool hasCaseModified(ParkingPermitsRequest request, Case existingVerintCase)
        {
            if (!string.Equals(existingVerintCase.Customer.Forename, request.FirstName, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (!string.Equals(existingVerintCase.Customer.Surname, request.LastName, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (!string.Equals(existingVerintCase.Customer.Email, request.Email, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(request.Phone) && existingVerintCase.Customer.Telephone != request.Phone)
            {
                return(true);
            }

            var newAddress = request.YourAddress.SelectedAddress.Split(',');
            var street     = existingVerintCase.Property.Description.Split(',')[0];

            if (!street.Equals(newAddress[0]))
            {
                return(true);
            }

            if (!string.Equals(existingVerintCase.Customer.Address.Postcode, newAddress.Last().Trim(), StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (!existingVerintCase.Description.Replace("\n", string.Empty).Equals(request.Description.Replace("\r\n", string.Empty)))
            {
                return(true);
            }

            return(false);
        }
        public Case ConvertPermitRequestToVerintCase(ParkingPermitsRequest request)
        {
            var address = new Address
            {
                AddressLine1 = request.YourAddress.AddressLine1,
                AddressLine2 = request.YourAddress.AddressLine2,
                AddressLine3 = request.YourAddress.Town,
                City         = request.YourAddress.Town,
                Postcode     = request.YourAddress.Postcode,
                UPRN         = request.YourAddress.PlaceRef,
                Reference    = request.YourAddress.PlaceRef,
                Description  = request.YourAddress.ToString()
            };

            var verintCase = new Case
            {
                EventCode      = Int32.Parse(_configuration.GetSection(ParkingPermitCaseSetting).GetSection("EventCode").Value),
                EventTitle     = request.Title,
                Description    = request.Description,
                Classification = _configuration.GetSection(ParkingPermitCaseSetting).GetSection("Classification").Value,
                Customer       = new Customer
                {
                    Forename  = request.FirstName,
                    Surname   = request.LastName,
                    Email     = request.Email,
                    Telephone = request.Phone,
                    Address   = string.IsNullOrEmpty(request.YourAddress.PlaceRef) ? address : new Address
                    {
                        Reference   = request.YourAddress.PlaceRef,
                        UPRN        = request.YourAddress.PlaceRef,
                        Description = request.YourAddress.SelectedAddress
                    },
                },
                Property = address,
                AssociatedWithBehaviour = AssociatedWithBehaviourEnum.Property
            };

            return(verintCase);
        }
示例#5
0
 public ActionResult <string> Get([FromQuery] ParkingPermitsRequest request)
 => request.ChargeFreeText;
示例#6
0
 public ActionResult <string> Calculate([FromQuery] ParkingPermitsRequest request)
 => request.CalculatedCost;
示例#7
0
 public async Task <ActionResult <string> > Post([FromBody] ParkingPermitsRequest parkingPermitsRequest)
 => await _parkingPermitsService.CreateCase(parkingPermitsRequest);
        public async Task <string> CreateCase(ParkingPermitsRequest parkingPermitsRequest)
        {
            if (!string.IsNullOrEmpty(parkingPermitsRequest.CaseReference))
            {
                HttpResponse <Case> existingVerintCase = await _verintServiceGateway.GetCase(parkingPermitsRequest.CaseReference);

                if (existingVerintCase != null)
                {
                    if (!_permitHelper.hasCaseModified(parkingPermitsRequest, existingVerintCase.ResponseContent))
                    {
                        return(parkingPermitsRequest.CaseReference);
                    }

                    HttpResponse <string> caseClosedResponse = await _verintServiceGateway.CloseCase(new CloseCaseRequest()
                    {
                        CaseReference = parkingPermitsRequest.CaseReference,
                        Description   = PermitConstants.STATUS_CLOSED,
                        ReasonTitle   = PermitConstants.STATUS_CLOSED,
                    });

                    if (!caseClosedResponse.IsSuccessStatusCode)
                    {
                        throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                        $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                        $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.CloseCase)} " +
                                                        $"failed with {caseClosedResponse.StatusCode}");
                    }
                }
            }

            var verintCase = _permitHelper.ConvertPermitRequestToVerintCase(parkingPermitsRequest);

            HttpResponse <string> response = await _verintServiceGateway.CreateCase(verintCase);

            if (!response.IsSuccessStatusCode || string.IsNullOrEmpty(response.ResponseContent))
            {
                throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.CreateCase)} " +
                                                $"failed with {response.StatusCode}");
            }

            var caseRef = response.ResponseContent;

            try
            {
                if (parkingPermitsRequest.File != null && parkingPermitsRequest.File.Any())
                {
                    foreach (var file in parkingPermitsRequest.File)
                    {
                        var attachment = file;
                        var note       = new NoteWithAttachments
                        {
                            CaseRef = long.Parse(caseRef),
                            AttachmentsDescription = attachment.TrustedOriginalFileName,
                            Attachments            = new List <File> {
                                file
                            }
                        };

                        var noteResponse = await _verintServiceGateway.AddNoteWithAttachments(note);

                        if (!noteResponse.IsSuccessStatusCode || noteResponse == null)
                        {
                            throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                            $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                            $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.AddNoteWithAttachments)} " +
                                                            $"failed with {noteResponse.StatusCode}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"ParkingEnforcementService::AddNoteWithAttachments, an exception has occurred while adding note with attachment to case: {response.ResponseContent}", ex);
            }

            if (!parkingPermitsRequest.CalculatedCost.Equals(PermitConstants.FREE_PRICE))
            {
                try
                {
                    await _distributedCache.SetStringAsync(caseRef, JsonSerializer.Serialize(parkingPermitsRequest),
                                                           new DistributedCacheEntryOptions { AbsoluteExpiration = DateTime.Now.AddMinutes(60) });
                }
                catch (Exception exception)
                {
                    throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                    $"{nameof(ParkingPermitsService)}: {nameof(CreateCase)}: " +
                                                    $"{nameof(_distributedCache)} failed - Verint Case Ref: " +
                                                    $"{caseRef}, message: {exception.Message}");
                }
            }

            if (parkingPermitsRequest.CalculatedCost.Equals(PermitConstants.FREE_PRICE))
            {
                _mailHelper.SendParkingPermitEmail(EMailTemplate.GenericReport, caseRef, parkingPermitsRequest);
            }

            return(caseRef);
        }
        public async Task UpdateCase(PostPaymentUpdateRequest update)
        {
            HttpResponse <Case> response = await _verintServiceGateway.GetCase(update.Reference);

            if (!response.IsSuccessStatusCode || response.ResponseContent is null)
            {
                throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                $"{nameof(ParkingPermitsService)}: {nameof(UpdateCase)}: " +
                                                $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.GetCase)} " +
                                                $"returned {response.StatusCode}");
            }

            var paymentMessage = update.PaymentStatus.ToPaymentString();

            Case crmCase = response.ResponseContent;

            string cachedResponse = await _distributedCache.GetStringAsync(update.Reference);

            if (string.IsNullOrEmpty(cachedResponse))
            {
                throw new HttpResponseException(HttpStatusCode.FailedDependency,
                                                $"{nameof(ParkingPermitsService)}: {nameof(UpdateCase)}: " +
                                                $"{nameof(_distributedCache)}: Verint Reference = {update.Reference}, " +
                                                $"{nameof(cachedResponse)} {nameof(string.IsNullOrEmpty)}");
            }

            ParkingPermitsRequest parkingPermitsRequest = JsonSerializer.Deserialize <ParkingPermitsRequest>(cachedResponse);

            crmCase.CaseTitle = parkingPermitsRequest.WhatApplication switch
            {
                PermitConstants.NEW_RESIDENT_PERMIT_VALUE => $"{PermitConstants.NEW_RESIDENT_PERMIT_TEXT} - {paymentMessage}",
                PermitConstants.NEW_VISITOR_PERMIT_VALUE => $"{PermitConstants.NEW_VISITOR_PERMIT_TEXT} - {paymentMessage}",
                PermitConstants.RENEW_RESIDENT_PERMIT_VALUE => $"{PermitConstants.RENEW_RESIDENT_PERMIT_TEXT} - {paymentMessage}",
                PermitConstants.RENEW_VISITOR_PERMIT_VALUE => $"{PermitConstants.RENEW_VISITOR_PERMIT_TEXT} - {paymentMessage}",
                _ => string.Empty
            };

            if (update.PaymentStatus.Equals(EPaymentStatus.Success))
            {
                int amountTakenPostion = crmCase.Description.IndexOf("Amount taken:");
                if (amountTakenPostion >= 0)
                {
                    crmCase.Description = $"{crmCase.Description.Substring(0, amountTakenPostion)} Amount taken: £{parkingPermitsRequest.CalculatedCost}";
                }

                var updateCasedescription = await _verintServiceGateway.UpdateCaseDescription(crmCase);

                if (!updateCasedescription.IsSuccessStatusCode)
                {
                    _logger.LogError($"{nameof(ParkingPermitsService.UpdateCase)}: " +
                                     $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.UpdateCaseDescription)} " +
                                     $"{crmCase.CaseReference} failed");
                }

                _mailHelper.SendParkingPermitEmail(EMailTemplate.GenericReport, update.Reference, parkingPermitsRequest);
            }

            var updateCaseTitle = await _verintServiceGateway.UpdateCaseTitle(crmCase);

            if (!updateCaseTitle.IsSuccessStatusCode)
            {
                _logger.LogError($"{nameof(ParkingPermitsService.UpdateCase)}: " +
                                 $"{nameof(_verintServiceGateway)} {nameof(_verintServiceGateway.UpdateCaseTitle)} " +
                                 $"{crmCase.CaseReference} failed");
            }
        }