public async Task Handle(eFormCompleted message)
        {
            WriteLogEntry($"eFormCompletedHandler.Handle: we got called for message.caseId {message.caseId} and message.checkId {message.checkId}");
            await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
            Language language = await microtingDbContext.Languages.SingleAsync(x => x.LanguageCode == "da");

            CaseDto caseDto = await _sdkCore.CaseLookup(message.caseId, message.checkId).ConfigureAwait(false);

            ReplyElement replyElement = await _sdkCore.CaseRead(message.caseId, message.checkId, language).ConfigureAwait(false);

            OuterInnerResourceSite machineAreaSite =
                _dbContext.OuterInnerResourceSites.SingleOrDefault(x =>
                                                                   x.MicrotingSdkCaseId == message.caseId);

            var machineAreaTimeRegistrations =
                await _dbContext.ResourceTimeRegistrations.Where(x =>
                                                                 // x.DoneAt == replyElement.DoneAt &&
                                                                 x.SDKCaseId == (int)caseDto.CaseId &&
                                                                 x.SDKSiteId == machineAreaSite.MicrotingSdkSiteId).ToListAsync().ConfigureAwait(false);

            if (machineAreaTimeRegistrations.Count == 0)
            {
                ResourceTimeRegistration machineAreaTimeRegistration = new ResourceTimeRegistration();
                if (machineAreaSite != null)
                {
                    var outerInnerResource =
                        await _dbContext.OuterInnerResources.SingleOrDefaultAsync(x =>
                                                                                  x.Id == machineAreaSite.OuterInnerResourceId);

                    machineAreaTimeRegistration.OuterResourceId = outerInnerResource.OuterResourceId;
                    machineAreaTimeRegistration.InnerResourceId = outerInnerResource.InnerResourceId;
                    machineAreaTimeRegistration.DoneAt          = replyElement.DoneAt;
                    if (caseDto.CaseId != null)
                    {
                        machineAreaTimeRegistration.SDKCaseId = (int)caseDto.CaseId;
                    }
                    machineAreaTimeRegistration.SDKSiteId = machineAreaSite.MicrotingSdkSiteId;
                }

                CheckListValue dataElement = (CheckListValue)replyElement.ElementList[0];
                foreach (var field in dataElement.DataItemList)
                {
                    Field f = (Field)field;
                    if (f.Label.ToLower().Contains("start/stop tid"))
                    {
                        try
                        {
                            Console.WriteLine($"The field is {f.Label}");
                            FieldValue fv         = f.FieldValues[0];
                            String     fieldValue = fv.Value;
                            if (!string.IsNullOrEmpty(fieldValue))
                            {
                                Console.WriteLine($"Current field_value is {fieldValue}");
                                int registeredTime = int.Parse(fieldValue.Split("|")[3]);
                                Console.WriteLine($"We are setting the registered time to {registeredTime.ToString()}");

                                machineAreaTimeRegistration.SDKFieldValueId = fv.Id;
                                machineAreaTimeRegistration.TimeInSeconds   = (registeredTime / 1000);
                                machineAreaTimeRegistration.TimeInMinutes   = ((registeredTime / 1000) / 60);
                                machineAreaTimeRegistration.TimeInHours     = ((registeredTime / 1000) / 3600);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }

                await machineAreaTimeRegistration.Create(_dbContext).ConfigureAwait(false);
            }
            else
            {
                if (machineAreaTimeRegistrations.Count > 1)
                {
                    int i = 0;
                    foreach (ResourceTimeRegistration machineAreaTimeRegistration in machineAreaTimeRegistrations)
                    {
                        if (i > 0)
                        {
                            await machineAreaTimeRegistration.Delete(_dbContext);
                        }

                        i++;
                        Console.WriteLine("More than one time registration found");
                    }
                }
                else
                {
                    Console.WriteLine("One time registration found");
                }
            }
        }
        #pragma warning disable 1998
        public async Task Handle(eFormCompleted message)
        {
            Console.WriteLine("[DBG] TrashInspection: We got a message : " + message.caseId);
            TrashInspectionCase trashInspectionCase =
                _dbContext.TrashInspectionCases.SingleOrDefault(x => x.SdkCaseId == message.caseId.ToString());

            if (trashInspectionCase != null)
            {
                #region get case information

                CaseDto caseDto = await _sdkCore.CaseLookupMUId(message.caseId);

                await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
                var      microtingUId      = caseDto.MicrotingUId;
                var      microtingCheckUId = caseDto.CheckUId;
                Language language          = await microtingDbContext.Languages.SingleAsync(x => x.Name == "Danish");

                ReplyElement theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language);

                CheckListValue dataElement        = (CheckListValue)theCase.ElementList[0];
                bool           inspectionApproved = false;
                string         approvedValue      = "";
                string         comment            = "";
                Console.WriteLine("[DBG] Trying to find the field with the approval value");
                foreach (var field in dataElement.DataItemList)
                {
                    Field f = (Field)field;
                    if (f.Label.Contains("Angiv om læs er Godkendt"))
                    {
                        Console.WriteLine($"The field is {f.Label}");
                        FieldValue fv         = f.FieldValues[0];
                        String     fieldValue = fv.Value;
                        inspectionApproved = (fieldValue == "1");
                        approvedValue      = fieldValue;
                        Console.WriteLine($"[DBG] We are setting the approved state to {inspectionApproved.ToString()}");
                    }

                    if (f.Label.Equals("Kommentar"))
                    {
                        Console.WriteLine($"[DBG] The field is {f.Label}");
                        FieldValue fv         = f.FieldValues[0];
                        String     fieldValue = fv.Value;
                        comment = fieldValue;
                        Console.WriteLine($"[DBG] We are setting the comment to {comment.ToString()}");
                    }
                }
                #endregion

                Console.WriteLine("TrashInspection: The incoming case is a trash inspection related case");
                trashInspectionCase.Status = 100;
                await trashInspectionCase.Update(_dbContext);

                TrashInspection trashInspection =
                    _dbContext.TrashInspections.SingleOrDefault(x => x.Id == trashInspectionCase.TrashInspectionId);
                if (trashInspection != null)
                {
                    trashInspection.Status         = 100;
                    trashInspection.IsApproved     = inspectionApproved;
                    trashInspection.Comment        = comment;
                    trashInspection.ApprovedValue  = approvedValue;
                    trashInspection.InspectionDone = true;
                    await trashInspection.Update(_dbContext);

                    List <TrashInspectionCase> trashInspectionCases = _dbContext.TrashInspectionCases
                                                                      .Where(x => x.TrashInspectionId == trashInspection.Id).ToList();
                    foreach (TrashInspectionCase inspectionCase in trashInspectionCases)
                    {
                        if (await _sdkCore.CaseDelete(int.Parse(inspectionCase.SdkCaseId)))
                        {
                            inspectionCase.WorkflowState = Constants.WorkflowStates.Retracted;
                            await inspectionCase.Update(_dbContext);
                        }
                    }

                    #region get settings

                    string callBackUrl = _dbContext.PluginConfigurationValues
                                         .SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:callBackUrl")?.Value;
                    Console.WriteLine("[DBG] callBackUrl is : " + callBackUrl);

                    string callBackCredentialDomain = _dbContext.PluginConfigurationValues.SingleOrDefault(x =>
                                                                                                           x.Name == "TrashInspectionBaseSettings:CallBackCredentialDomain")?.Value;
                    Console.WriteLine("[DBG] callBackCredentialDomain is : " + callBackCredentialDomain);

                    string callbackCredentialUserName = _dbContext.PluginConfigurationValues.SingleOrDefault(x =>
                                                                                                             x.Name == "TrashInspectionBaseSettings:callbackCredentialUserName")?.Value;
                    Console.WriteLine("[DBG] callbackCredentialUserName is : " + callbackCredentialUserName);

                    string callbackCredentialPassword = _dbContext.PluginConfigurationValues.SingleOrDefault(x =>
                                                                                                             x.Name == "TrashInspectionBaseSettings:CallbackCredentialPassword")?.Value;
                    Console.WriteLine("[DBG] callbackCredentialPassword is : " + callbackCredentialPassword);

                    string callbackCredentialAuthType = _dbContext.PluginConfigurationValues.SingleOrDefault(x =>
                                                                                                             x.Name == "TrashInspectionBaseSettings:CallbackCredentialAuthType")?.Value;
                    Console.WriteLine("[DBG] callbackCredentialAuthType is : " + callbackCredentialAuthType);

                    Console.WriteLine($"[DBG] trashInspection.WeighingNumber is {trashInspection.WeighingNumber}");
                    #endregion

                    switch (callbackCredentialAuthType)
                    {
                    case "NTLM":
                        await CallUrlNtlmAuth(callBackUrl, callBackCredentialDomain, callbackCredentialUserName,
                                              callbackCredentialPassword, trashInspection, inspectionApproved);

                        break;

                    case "basic":
                    default:
                        await CallUrlBaiscAuth(callBackUrl, callBackCredentialDomain, callbackCredentialUserName,
                                               callbackCredentialPassword, trashInspection, inspectionApproved);

                        break;
                    }
                }
            }
        }