예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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();
        }
예제 #3
0
        /// <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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        /// <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();
        }
예제 #6
0
 /// <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());
 }
예제 #7
0
 /// <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());
 }
예제 #8
0
 /// <summary>
 /// Gets all.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public List <Project> GetAll(TreeNotebookEntities context)
 {
     return(context.Projects.ToList());
 }
예제 #9
0
 /// <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());
 }
예제 #10
0
 /// <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());
 }
예제 #11
0
 /// <summary>
 /// Gets all.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public List <Node> GetAll(TreeNotebookEntities context)
 {
     return(context.Nodes.ToList());
 }