public void EnterEquipmentNode(string parentNodeId, int selectedEquipmentId, int selectedEquipmentAttributeId, int treeId)
        {
            int parentID = int.Parse(parentNodeId);
           
            var parentNode = db.Nodes.Find(parentID);
            parentNode.NodeValue = selectedEquipmentId;
            parentNode.SecondaryNodeValue = selectedEquipmentAttributeId;
            parentNode.EquipmentNode = true;
            parentNode.PatientAttributeNode = false;
            parentNode.SolutionNode = false;
            db.Entry(parentNode).State = EntityState.Modified;
            db.SaveChanges();

            var nodesToAdd = new List<Node>();

            var equipmentAttributeValues = db.EquipmentAttributes.Find(selectedEquipmentAttributeId).EquipmentAttributeValues;
            foreach (var av in equipmentAttributeValues)
            {
                var childNode = new Node
                {
                    ParentID = parentNode.ID,
                    TreeID = treeId,
                    EdgeOperator = "==",
                    EdgeValue = av.ID,
                    Numeric = false
                };
                nodesToAdd.Add(childNode);
            }
        
            db.Nodes.AddRange(nodesToAdd);
            db.SaveChanges();

        }
        //Tree Methods
        public void EnterAttributeNode(string parentNodeId, int selectedAttributeId, int treeId, Boolean selectedAttributeNumeric, string selectedAttributeNumericValue)
        {
            //ParentNodeID is the ID of the node that was selected by the user. It is named ParentNodeID, as it is about to become a parent node
            int parentID = 0;
            Boolean parentNodeExists = int.TryParse(parentNodeId, out parentID);
            var parentNode = new Node();

            //this if statement only runs when the first node is inserted
            if (!parentNodeExists)
            {
                parentID = 0;
                parentNode = new Node
                {
                    NodeValue = selectedAttributeId,
                    ParentID = parentID,
                    TreeID = treeId, 
                    PatientAttributeNode = true,
                    EquipmentNode = false, 
                    SolutionNode = false
                };
                db.Nodes.Add(parentNode);
                db.SaveChanges();
            }
            else
            {
                parentNode = db.Nodes.Find(parentID);
                parentNode.NodeValue = selectedAttributeId;
                parentNode.PatientAttributeNode = true;
                parentNode.SolutionNode = false;
                parentNode.EquipmentNode = false;
                db.Entry(parentNode).State = EntityState.Modified;
                db.SaveChanges();
            }

            var nodesToAdd = new List<Node>();
            if (selectedAttributeNumeric)
            {
                var childNodeA = new Node
                {
                    ParentID = parentNode.ID,
                    TreeID = treeId,
                    EdgeOperator = "<=",
                    EdgeValue = int.Parse(selectedAttributeNumericValue),
                    Numeric = true
                };
                var childNodeB = new Node
                {
                    ParentID = parentNode.ID,
                    TreeID = treeId,
                    EdgeOperator = ">",
                    EdgeValue = int.Parse(selectedAttributeNumericValue),
                    Numeric = true
                };
                nodesToAdd.Add(childNodeA);
                nodesToAdd.Add(childNodeB);
            }
            else
            {
                var attributeValues = db.PatientAttributes.Find(selectedAttributeId).PatientAttributeValues;
                foreach (var av in attributeValues)
                {
                    var childNode = new Node
                    {
                        ParentID = parentNode.ID,
                        TreeID = treeId,
                        EdgeOperator = "==",
                        EdgeValue = av.ID,
                        Numeric = false
                    };
                    nodesToAdd.Add(childNode);
                }
            }
            db.Nodes.AddRange(nodesToAdd);
            db.SaveChanges();
        }
        private Boolean checkBranch(Patient patient, Node parentNode, Node childNode)
        {
            if (parentNode.PatientAttributeNode)
            {
                var patientAttribute = db.PatientAttributes.Single(i => i.ID == parentNode.NodeValue);
                var patientsPatientAttributeValue = db.Patient_PatientAttributes.Single(i => i.PatientID == patient.ID && i.PatientAttributeID == patientAttribute.ID).PatientAttributeValue;
                int number1;
                int number2;
                switch (childNode.EdgeOperator)
                {
                    case "==":
                        var edgePatientAttributeValue = db.PatientAttributeValues.Single(i => i.ID == childNode.EdgeValue);
                        if (edgePatientAttributeValue.ID == patientsPatientAttributeValue.ID)
                            return true;
                        else
                            return false;
                    case "<=":
                        number1 = int.Parse(patientsPatientAttributeValue.Value);
                        number2 = childNode.EdgeValue;

                        if (number1 <= number2)
                            return true;
                        else
                            return false;
                    case ">":
                        number1 = int.Parse(patientsPatientAttributeValue.Value);
                        number2 = childNode.EdgeValue;

                        if (number1 > number2)
                            return true;
                        else
                            return false;
                }
            }
            else //node is an equipment node
            {
                var equipment = db.Equipment.Find(parentNode.NodeValue);
                var equipmentAttribute = db.EquipmentAttributes.Find(parentNode.SecondaryNodeValue);
                var edgeValue = childNode.EdgeValue;

                if (edgeValue == equipmentAttribute.CurrentEquipmentAttributeValueID)
                    return true;
                else
                    return false;
            }
            return false; //this should never be executed
        }