public async Task Handle(eFormCaseUpdated message) { ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId); if (itemCaseSite != null) { var caseDto = await _sdkCore.CaseReadByCaseId(message.caseId); var microtingUId = caseDto.MicrotingUId; var microtingCheckUId = caseDto.CheckUId; await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext(); Site site = await microtingDbContext.Sites.SingleAsync(x => x.Id == itemCaseSite.MicrotingSdkSiteId); Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId); var theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language); itemCaseSite = await SetFieldValue(itemCaseSite, theCase.Id); await itemCaseSite.Update(_dbContext); ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.Id == itemCaseSite.ItemCaseId); itemCase = await SetFieldValue(itemCase, theCase.Id); await itemCase.Update(_dbContext); } }
public async Task Handle(eFormRetrieved message) { ItemCaseSite itemCaseSite = _dbContext.ItemCaseSites.SingleOrDefault(x => x.MicrotingSdkCaseId == message.caseId); if (itemCaseSite != null) { if (itemCaseSite.Status < 77) { itemCaseSite.Status = 77; await itemCaseSite.Update(_dbContext); } } }
public async Task Handle(eFormCompleted message) { ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId); if (itemCaseSite != null) { itemCaseSite.Status = 100; var caseDto = _sdkCore.CaseReadByCaseId(message.caseId); var microtingUId = caseDto.Result.MicrotingUId; var microtingCheckUId = caseDto.Result.CheckUId; // if (microtingUId != null && microtingCheckUId != null) {} if (microtingUId != null && microtingCheckUId != null) { Language language = await _sdkCore.DbContextHelper.GetDbContext().Languages .SingleAsync(x => x.LanguageCode == "da"); var theCase = _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language); itemCaseSite = await SetFieldValue(itemCaseSite, theCase.Id); itemCaseSite.MicrotingSdkCaseDoneAt = theCase.Result.DoneAt; itemCaseSite.DoneByUserId = itemCaseSite.MicrotingSdkSiteId; var site = _sdkCore.SiteRead(itemCaseSite.MicrotingSdkSiteId); itemCaseSite.DoneByUserName = $"{site.Result.FirstName} {site.Result.LastName}"; await itemCaseSite.Update(_dbContext); ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.Id == itemCaseSite.ItemCaseId); if (itemCase.Status != 100) { itemCase.Status = 100; itemCase.MicrotingSdkCaseDoneAt = theCase.Result.DoneAt; itemCase.MicrotingSdkCaseId = itemCaseSite.MicrotingSdkCaseId; itemCase.DoneByUserId = itemCaseSite.MicrotingSdkSiteId; itemCase.DoneByUserName = $"{site.Result.FirstName} {site.Result.LastName}"; itemCase = await SetFieldValue(itemCase, theCase.Id); await itemCase.Update(_dbContext); } await RetractFromMicroting(itemCase.Id); } } }
public async Task Handle(ItemCaseCreate message) { Item item = await _dbContext.Items.SingleOrDefaultAsync(x => x.Id == message.ItemId); if (item != null) { var siteIds = await _dbContext.PluginConfigurationValues.FirstOrDefaultAsync(x => x.Name == "ItemsPlanningBaseSettings:SiteIds"); Language language = await _sdkCore.DbContextHelper.GetDbContext().Languages .SingleAsync(x => x.LanguageCode == "da"); var mainElement = _sdkCore.ReadeForm(message.RelatedEFormId, language); string folderId = GetFolderId(message.Name).ToString(); ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.ItemId == item.Id && x.WorkflowState != Constants.WorkflowStates.Retracted); if (itemCase != null) { itemCase.WorkflowState = Constants.WorkflowStates.Retracted; await itemCase.Update(_dbContext); } itemCase = new ItemCase { ItemId = item.Id, Status = 66, MicrotingSdkeFormId = message.RelatedEFormId }; await itemCase.Create(_dbContext); foreach (var siteIdString in siteIds.Value.Split(',')) { var siteId = int.Parse(siteIdString); var casesToDelete = _dbContext.ItemCaseSites. Where(x => x.ItemId == item.Id && x.MicrotingSdkSiteId == siteId && x.WorkflowState != Constants.WorkflowStates.Retracted); foreach (ItemCaseSite caseToDelete in casesToDelete) { CaseDto caseDto = await _sdkCore.CaseLookupCaseId(caseToDelete.MicrotingSdkCaseId); if (caseDto.MicrotingUId != null) { await _sdkCore.CaseDelete((int)caseDto.MicrotingUId); } caseToDelete.WorkflowState = Constants.WorkflowStates.Retracted; await caseToDelete.Update(_dbContext); } mainElement.Result.Label = string.IsNullOrEmpty(item.ItemNumber) ? "" : item.ItemNumber; if (!string.IsNullOrEmpty(item.Name)) { mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.Name}" : $" - {item.Name}"; } if (!string.IsNullOrEmpty(item.BuildYear)) { mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.BuildYear}" : $" - {item.BuildYear}"; } if (!string.IsNullOrEmpty(item.Type)) { mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.Type}" : $" - {item.Type}"; } mainElement.Result.ElementList[0].Label = mainElement.Result.Label; mainElement.Result.CheckListFolderName = folderId; mainElement.Result.StartDate = DateTime.Now.ToUniversalTime(); mainElement.Result.EndDate = DateTime.Now.AddYears(10).ToUniversalTime(); ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.ItemCaseId == itemCase.Id && x.MicrotingSdkSiteId == siteId); if (itemCaseSite == null) { itemCaseSite = new ItemCaseSite { MicrotingSdkSiteId = siteId, MicrotingSdkeFormId = message.RelatedEFormId, Status = 66, ItemId = item.Id, ItemCaseId = itemCase.Id }; await itemCaseSite.Create(_dbContext); } if (itemCaseSite.MicrotingSdkCaseId >= 1) { continue; } int?caseId = await _sdkCore.CaseCreate(await mainElement, "", siteId, null); if (caseId != null) { CaseDto caseDto = await _sdkCore.CaseLookupMUId((int)caseId); if (caseDto?.CaseId != null) { itemCaseSite.MicrotingSdkCaseId = (int)caseDto.CaseId; } await itemCaseSite.Update(_dbContext); } } } }
private async Task <ItemCaseSite> SetFieldValue(ItemCaseSite itemCaseSite, int caseId) { Item item = _dbContext.Items.SingleOrDefault(x => x.Id == itemCaseSite.ItemId); ItemList itemList = _dbContext.ItemLists.SingleOrDefault(x => x.Id == item.ItemListId); List <int> caseIds = new List <int>(); caseIds.Add(itemCaseSite.MicrotingSdkCaseId); await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext(); Site site = await microtingDbContext.Sites.SingleAsync(x => x.Id == itemCaseSite.MicrotingSdkSiteId); Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId); List <FieldValue> fieldValues = await _sdkCore.Advanced_FieldValueReadList(caseIds, language); if (itemList == null) { return(itemCaseSite); } if (itemList.SdkFieldEnabled1) { itemCaseSite.SdkFieldValue1 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId1)?.ValueReadable; } if (itemList.SdkFieldEnabled2) { itemCaseSite.SdkFieldValue2 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId2)?.ValueReadable; } if (itemList.SdkFieldEnabled3) { itemCaseSite.SdkFieldValue3 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId3)?.ValueReadable; } if (itemList.SdkFieldEnabled4) { itemCaseSite.SdkFieldValue4 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId4)?.ValueReadable; } if (itemList.SdkFieldEnabled5) { itemCaseSite.SdkFieldValue5 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId5)?.ValueReadable; } if (itemList.SdkFieldEnabled6) { itemCaseSite.SdkFieldValue6 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId6)?.ValueReadable; } if (itemList.SdkFieldEnabled7) { itemCaseSite.SdkFieldValue7 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId7)?.ValueReadable; } if (itemList.SdkFieldEnabled8) { itemCaseSite.SdkFieldValue8 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId8)?.ValueReadable; } if (itemList.SdkFieldEnabled9) { itemCaseSite.SdkFieldValue9 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId9)?.ValueReadable; } if (itemList.SdkFieldEnabled10) { itemCaseSite.SdkFieldValue10 = fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId10)?.ValueReadable; } if (itemList.NumberOfImagesEnabled) { itemCaseSite.NumberOfImages = 0; foreach (FieldValue fieldValue in fieldValues) { if (fieldValue.FieldType == Constants.FieldTypes.Picture) { if (fieldValue.UploadedData != null) { itemCaseSite.NumberOfImages += 1; } } } } return(itemCaseSite); }