/// <summary>
        /// Removes the project by unique identifier.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="projectId">The project unique identifier.</param>
        public void RemoveProjectById(TreeNotebookEntities context, int projectId)
        {
            Project projectForRemove = GetById(context, projectId);
            context.Projects.Remove(projectForRemove);

            context.SaveChanges();
        }
        /// <summary>
        /// Adds the new.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="projectName">Name of the project.</param>
        public void AddNew(TreeNotebookEntities context, string projectName)
        {
            Project project = new Project()
            {
                Name = projectName,
            };

            context.Projects.Add(project);
            context.SaveChanges();
        }
 /// <summary>
 /// Removes the node by unique identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="nodeId">The node unique identifier.</param>
 public void RemoveNodeById(TreeNotebookEntities context, int nodeId)
 {
     Node nodeForRemove = GetById(context, nodeId);
     List<Node> childNodes = GetAllChildNodesByMainNodeId(context, nodeForRemove.NodeId);
     foreach (var currentChild in childNodes)
     {
         this.RemoveNodeById(context, currentChild.NodeId);
     }
     context.Nodes.Remove(nodeForRemove);
    
     context.SaveChanges();
 }
        public void Update(TreeNotebookEntities context, string nodeXml = "", int? parentNodeId = null)
        {
            Node newNode = new Node()
            {
                NodeXml = nodeXml,
                CreationDateTime = DateTime.Now,
                ParentNodeId = parentNodeId
            };

            context.Nodes.Add(newNode);
            context.SaveChanges();
        }
 /// <summary>
 /// Gets the main node by project unique identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="projectId">The project unique identifier.</param>
 /// <returns>the found main node</returns>
 public Node GetMainNodeByProjectId(TreeNotebookEntities context, int projectId)
 {
     ProjectsNode currentProjectNode = context.ProjectsNodes.Where(p => p.ProjectId == projectId).FirstOrDefault();
     Node resultNode = context.Nodes.Where(p => p.NodeId == currentProjectNode.NodeId).FirstOrDefault();
     return resultNode;
 }
 /// <summary>
 /// Gets the by unique identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="projectId">The project unique identifier.</param>
 /// <returns></returns>
 public Project GetById(TreeNotebookEntities context, int projectId)
 {
     return context.Projects.Where(p => p.ProjectId.Equals(projectId)).FirstOrDefault();
 }
 /// <summary>
 /// Gets the name of the by.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public Project GetByName(TreeNotebookEntities context, string name)
 {
     return context.Projects.Where(p => p.Name.Equals(name)).FirstOrDefault();
 }
 /// <summary>
 /// Gets all.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public List<Project> GetAll(TreeNotebookEntities context)
 {
     return context.Projects.ToList();
 }
 /// <summary>
 /// Gets all child nodes by main node unique identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="nodeID">The node unique identifier.</param>
 /// <returns></returns>
 public List<Node> GetAllChildNodesByMainNodeId(TreeNotebookEntities context, int nodeID)
 {
     return context.Nodes.Where(p => p.ParentNodeId.Equals(nodeID)).ToList();
 }
 /// <summary>
 /// Gets the by unique identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="nodeID">The node unique identifier.</param>
 /// <returns>the found node</returns>
 public Node GetById(TreeNotebookEntities context, int nodeID)
 {
     return context.Nodes.Where(p => p.NodeId.Equals(nodeID)).FirstOrDefault();
 }
 /// <summary>
 /// Gets all.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public List<Node> GetAll(TreeNotebookEntities context)
 {
     return context.Nodes.ToList();
 }