/// <summary> /// Handle a notification that a Green card request is canceled /// </summary> /// <param name="key"></param> /// <param name="assurBoxNotification"></param> private void ProcessCancellationRequest(string key, GreenCardRequestNotification assurBoxNotification) { using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var request = ctx.CarGreenCardRequests.FirstOrDefault(x => x.RequestId == key); request.ResponseInfo = "The green card request was cancelled : " + assurBoxNotification.Communication; request.RequestRespondDate = DateTime.UtcNow; ctx.SaveChanges(); } }
private bool ValidateRequest(GreenCardRequestNotification assurBoxNotification, out string validationMessage) { validationMessage = string.Empty; // in order to test, we defined that some Licence Plates should simulate a bad request switch (assurBoxNotification.LicencePlate.ToUpper()) { case "ER0404": { validationMessage = "Validation Error : we can't issue a green card for this client."; } break; case "ER0403": { validationMessage = "Validation Error : we can't issue a green card for this vehicle."; } break; default: break; } return(string.IsNullOrEmpty(validationMessage)); }
/// <summary> /// Handle a notification for a green card request /// </summary> /// <param name="key"></param> /// <param name="assurBoxNotification"></param> private void ProcessModificationRequest(string key, GreenCardRequestNotification assurBoxNotification) { // 1. retrieve a token to access the AssurBox Api var tokenInfo = AssurBoxSecurity.GetAssurBoxSecurityToken(); // 2. using the token, create a "greencard client" CarGreenCardClient client = new CarGreenCardClient(new AssurBoxClientOptions { Host = Config.AssurBoxApiBaseURL, ApiKey = tokenInfo }); // 3. using the authentified client, retrieve the details of the green card request // full detail about the customer, car information, ... var requestDetails = client.GetRequest(assurBoxNotification.CorrelationId).Result; // 4. do something with the request in your information system var document = GetDemoPDFUpdate(requestDetails); // 5. send a response to the requester, using the greencard client and a greencardrequestresponse object GreenCardRequestResponse response = new GreenCardRequestResponse(); // The correlation id identify a greencard request file (this is mandatory) response.CorrelationId = assurBoxNotification.CorrelationId; // The messageid identify a specific message (this is mandatory) response.MessageId = assurBoxNotification.MessageId; string validationMessage; if (ValidateRequest(assurBoxNotification, out validationMessage) == false) { // We can send a response refusing to issue a green card response.HasApproval = false; response.ApprovalReason = validationMessage; response.ResponseContent = validationMessage; } else { response.HasApproval = true; // don't forget to set this property to true // define a message for the requester response.ResponseContent = $@" Bonjour {assurBoxNotification.Requester.Name}, Merci pour votre demande, (type : {assurBoxNotification.NotificationType}) Voici votre carte mise à jour pour {assurBoxNotification.LicencePlate} Client : {requestDetails.CustomerName} Bien à vous, Assurance simulation demo ({requestDetails.InsuranceName}) "; // make sure the file is encoded as a base64 string response.AddAttachment($"CarteVerte_{assurBoxNotification.LicencePlate}.pdf", Convert.ToBase64String(document)); } // send the response to AssurBox var resp = client.SendResponse(response).Result; using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var request = ctx.CarGreenCardRequests.FirstOrDefault(x => x.RequestId == key); request.ResponseInfo = "Updated response " + resp.ResponseContent; request.RequestRespondDate = DateTime.UtcNow; ctx.SaveChanges(); } }