コード例 #1
0
        public async Task <IActionResult> Search([FromQuery] WorkflowNodeSearchRequest requestArgs)
        {
            return(await FunctionWrapper.ExecuteFunction(this, async() =>
            {
                if (string.IsNullOrEmpty(requestArgs.WorkflowId))
                {
                    throw new System.Exception("Invalid search parameters supplied.");
                }

                return await _workflowNodeRepository.Search(new ObjectId(requestArgs.WorkflowId));
            }));
        }
コード例 #2
0
        private async Task <Item> HydrateForGetAndSave(Item item)
        {
            try
            {
                // Clear linked items as they should not be saved
                item.LinkedItems = null;

                // Set Type from ID
                string typeId = item.TypeId.ToString();

                if (!tempItemTypeCache.ContainsKey(typeId))
                {
                    var itemType = await _itemTypeRepository.Get(item.TypeId);

                    if (itemType == null)
                    {
                        throw new ApplicationException("Invalid Type ID.");
                    }
                    tempItemTypeCache.Add(typeId, itemType);
                }
                item.Type = tempItemTypeCache[typeId];

                if (item.LocationId != null && item.LocationId != ObjectId.Empty)
                {
                    string locationId = item.LocationId.ToString();

                    if (!tempItemLocationCache.ContainsKey(locationId))
                    {
                        var loc = await _itemLocationRepository.Get(item.LocationId);

                        if (loc == null)
                        {
                            throw new ApplicationException("Invalid Location ID.");
                        }
                        tempItemLocationCache.Add(locationId, loc);
                    }
                    item.Location = tempItemLocationCache[locationId];
                }

                // Populate item's workflow node ID from default node from assoc. item type workflow
                // if not already set (should only be for new items)
                if (item.WorkflowNodeId == null || item.WorkflowNodeId == ObjectId.Empty)
                {
                    if (item.Type.WorkflowId == null || item.Type.WorkflowId == ObjectId.Empty)
                    {
                        throw new ApplicationException("Item does not have an associated workflow.");
                    }
                    var workflowNodes = await _workflowNodeRepository.Search(item.Type.WorkflowId);

                    var workflowNode = workflowNodes.FirstOrDefault();
                    if (workflowNode == null)
                    {
                        throw new ApplicationException("Associated workflow does not have any nodes.");
                    }
                    item.WorkflowNodeId = workflowNode.Id;
                }

                // Set Workflow Node from ItemType's associated Workflow
                string workflowNodeId = item.WorkflowNodeId.ToString();

                if (!tempWorkflorNodeCache.ContainsKey(workflowNodeId))
                {
                    var workflowNode = await _workflowNodeRepository.Get(item.WorkflowNodeId);

                    if (workflowNode == null)
                    {
                        throw new ApplicationException("Cannot find workflow node.");
                    }
                    tempWorkflorNodeCache.Add(workflowNodeId, workflowNode);
                }
                item.WorkflowNode = tempWorkflorNodeCache[workflowNodeId];

                return(item);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }