예제 #1
0
        public async Task <ActionResult <object> > PostRedeemIcc(RedeemIccModel redeemIccModel)
        {
            // Make Icc Used, so it can only be used once
            var infectionConfirmationCodeEntity = await _IccService.RedeemIcc(User.Identity.Name);

            _DbContext.SaveAndCommit();

            // POST /labresult call on App Backend
            bool isValid = false;

            try
            {
                isValid = await _AppBackendService.LabConfirmationIdIsValid(redeemIccModel);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            if (isValid)
            {
                // TODO: remove debugging Icc and payload from response
                return(new JsonResult(new
                {
                    ok = true,
                    status = 200,
                    payload = redeemIccModel
                }));
            }

            return(BadRequest(new
                              { ok = false, status = "400", message = "Invalid LabConfirmationId", payload = redeemIccModel }));
        }
        public async Task <bool> LabConfirmationIdIsValid(RedeemIccModel redeemIccModel)
        {
            var backendResponse =
                await BackendPostRequest("/v1/labConfirm",
                                         new AuthorisationArgs(redeemIccModel));

            if (backendResponse == null)
            {
                return(false);
            }
            var backendResponseJson = JsonConvert.DeserializeObject <Dictionary <string, bool> >(backendResponse);

            return(backendResponseJson != null && backendResponseJson["valid"]);
        }
 public AuthorisationArgs(RedeemIccModel redeemIccModel)
 {
     LabConfirmationId   = redeemIccModel.LabConfirmationId.Replace("-", string.Empty);
     DateOfSymptomsOnset = redeemIccModel.DateOfSymptomsOnset;
 }