public async Task <Item> Get(ObjectId id, ItemExpansionParams expand = null) { var filter = Builders <Item> .Filter.Eq("Id", id); if (expand == null) { expand = new ItemExpansionParams(null); } try { var item = await _context.Items.Find(filter).FirstOrDefaultAsync(); if (item == null) { throw new ApplicationException("Could not find item with ID:" + item.Id); } ResetTemporaryCaches(); await HydrateForGet(item, expand); return(item); } catch (Exception ex) { throw ex; } }
private async Task <Item> HydrateForGet(Item item, ItemExpansionParams expand) { try { item = await HydrateForGetAndSave(item); if (expand.LinkedItems) { if (item.LinkedItemIds != null && item.LinkedItemIds.Count > 0) { item.LinkedItems = new List <Item>(); foreach (ObjectId linkedItemId in item.LinkedItemIds) { if (item.LinkedItems == null) { item.LinkedItems = new List <Item>(); } item.LinkedItems.Add(await Get(linkedItemId)); } } } if (expand.Transitions) { var funcReg = new FunctionRegistry(this, _itemTypeRepository, null, _workflowNodeRepository); var nodeTransitions = await _workflowTransitionRepository .Search(new WorkflowTransitionSearchRequest() { FromNodeId = item.WorkflowNodeId.ToString() }); // Test each transitions conditions for applicability to the item foreach (WorkflowTransition transition in nodeTransitions) { bool anyFailedConditions = false; if (transition.PreConditions == null) { transition.PreConditions = new List <WorkflowTransitionFunction>(); } foreach (WorkflowTransitionFunction condition in transition.PreConditions) { var execResult = await funcReg .ExecuteFunction(condition, item); if (execResult.IsFailure) { anyFailedConditions = true; break; } } if (!anyFailedConditions) { if (item.Transitions == null) { item.Transitions = new List <WorkflowTransition>(); } item.Transitions.Add(transition); } } } return(item); } catch (Exception ex) { throw ex; } }