public HttpResponseMessage Post(SDK.WebHooks.GreenCardRequestNotification value) { if (value == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Parameter can't be null")); } Logger.Log($"CarGreenCardController.Post - Debut {value.CorrelationId}"); string key = $"{value.CorrelationId}|{value.MessageId}"; // Save the notification for later processing using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { ctx.CarGreenCardRequests.Add(new DAL.CarGreenCardRequest { RequestDate = DateTime.UtcNow, RequestId = key, RawRequest = JsonConvert.SerializeObject(value, Formatting.None), }); ctx.SaveChanges(); } // Creates a job that will be executed as soon as possible _jobClient.Enqueue(() => ExecuteJob(key)); Logger.Log("CarGreenCardController.Post - Fin"); // Don't forget to notify AssurBox that the notication is received return(Request.CreateResponse(HttpStatusCode.OK, value.CorrelationId)); }
public async Task <ActionResult> RequestDetail(int requestID) { using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var requ = await ctx.CarGreenCardRequests.FindAsync(requestID); return(View(requ)); } }
/// <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(); } }
public async Task <ActionResult> Logs() { LogsModel model = new LogsModel(); using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { model.Logs = await ctx.Logs.OrderByDescending(x => x.LogDate).ToListAsync(); } return(View(model)); }
// GET: Admin public async Task <ActionResult> Index() { AssurBox.Samples.API.Insurance.Models.AdminModel model = new Models.AdminModel(); using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { model.Requests = await ctx.CarGreenCardRequests.AsNoTracking() .OrderByDescending(x => x.RequestDate).Take(200).ToListAsync(); } return(View(model)); }
/// <summary> /// Ici on va traiter la demande que l'on a sauvegardée /// on récupère les infos /// on crée une réponse /// et on envoie la réponse à AssurBox via l'api /// </summary> /// <param name="key"></param> public void ExecuteJob(string key) { Logger.Log($"ContractTermination.ExecuteJob - Debut {key}"); // recherche dans la table SDK.WebHooks.AssurBoxWebHook assurBoxNotification; using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var request = ctx.CarGreenCardRequests.AsNoTracking().FirstOrDefault(x => x.RequestId == key); assurBoxNotification = JsonConvert.DeserializeObject <SDK.WebHooks.AssurBoxWebHook>(request.RawRequest); } // 1. retrieve a token to access the AssurBox Api var tokenInfo = AssurBoxSecurity.GetAssurBoxSecurityToken(); // 2. use the client SDK.Clients.ContractTerminationClient client = new SDK.Clients.ContractTerminationClient(new AssurBoxClientOptions { Host = Config.AssurBoxApiBaseURL, ApiKey = tokenInfo }); // 3. using the authentified client, retrieve the details of the request // full detail about the customer, car information, ... //var requestDetails = client.(assurBoxNotification.CorrelationId).Result; SDK.DTO.Contract.ContractTerminationInfo requestinfo = client.GetContractTerminationRequestAsync(assurBoxNotification.CorrelationId).Result; // 4. do something with the request in your information system // ... // 5. send a response to the requester string acceptation = GetAcceptation(requestinfo.Request.Risk); var resp = client.SendContractTerminationResponseAsync(new SDK.DTO.Contract.ContractTerminationResponse { CorrelationId = assurBoxNotification.CorrelationId, MessageId = assurBoxNotification.MessageId, Communication = acceptation, IsTerminationRequestAccepted = acceptation == "OK", EffectiveTerminationDate = DateTime.Today.AddDays(7) }).Result; // todo change "green card" using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var request = ctx.CarGreenCardRequests.FirstOrDefault(x => x.RequestId == key); request.ResponseInfo = "Response sent " + resp.ResponseContent; request.RequestRespondDate = DateTime.UtcNow; ctx.SaveChanges(); } }
/// <summary> /// Ici on va traiter la demande que l'on a sauvegardée /// on récupère les infos /// on crée une carte verte ou tout ce qu'on veut /// et on envoie la réponse à AssurBox via l'api /// </summary> /// <param name="key"></param> public void ExecuteJob(string key) { Logger.Log($"CarGreenCardController.ExecuteJob - Debut {key}"); // recherche dans la table GreenCardRequestNotification assurBoxNotification; using (DAL.ApiDataContext ctx = new DAL.ApiDataContext()) { var request = ctx.CarGreenCardRequests.AsNoTracking().FirstOrDefault(x => x.RequestId == key); assurBoxNotification = JsonConvert.DeserializeObject <SDK.WebHooks.GreenCardRequestNotification>(request.RawRequest); } switch (assurBoxNotification.NotificationType) { case SDK.WebHooks.GreenCardRequestNotificationTypes.InitialRequest: { // generates a sample green card and send it back to AssurBox ProcessInitialRequest(key, assurBoxNotification); } break; case SDK.WebHooks.GreenCardRequestNotificationTypes.Modification: { // generates a sample green card and send it back to AssurBox ProcessModificationRequest(key, assurBoxNotification); } break; case SDK.WebHooks.GreenCardRequestNotificationTypes.Cancelation: { ProcessCancellationRequest(key, assurBoxNotification); } break; default: { } break; } }
/// <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(); } }