Пример #1
0
        public static TaxNode GetById(int id)
        {
            var sqlCmd = $"select article_id, parent from tax_nodes where id = {id};";
            var cmd    = new NpgsqlCommand(sqlCmd, DBConnect.Connection);
            var reader = cmd.ExecuteReader();
            var node   = new Models.TaxNode();
            int count  = 0;

            while (reader.Read())
            {
                count++;
                node.Id        = id;
                node.ArticleId = reader.GetInt32(0);

                var obj      = reader.GetValue(1);
                var nullable = obj as DBNull;
                if (nullable == null)
                {
                    node.ParentNodeId = (int)obj;
                }
                else
                {
                    node.ParentNodeId = -1;
                }
            }
            reader.Close();
            cmd.Dispose();
            if (count == 0)
            {
                node = null;
            }
            return(node);
        }
Пример #2
0
        public static List <TaxNode> GetAllNodes()
        {
            List <TaxNode> nodes = new List <TaxNode>();
            //id=2- biota
            var sqltxt = $"SELECT t.* FROM tax_nodes t JOIN tax_nodes t2 ON t.left_bound >= t2.left_bound AND t.right_bound <= t2.right_bound WHERE t2.id = 2";

            var cmd    = new NpgsqlCommand(sqltxt, DBConnect.Connection);
            var reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                var node = new Models.TaxNode();
                node.Id = reader.GetInt32(0);
                var parent = reader.GetValue(1);

                var parentNull = parent as System.DBNull;

                node.ParentNodeId = parentNull != null ? 0 : (int)parent;
                node.LeftBound    = reader.GetInt32(2);
                node.RightBound   = reader.GetInt32(3);
                node.ArticleId    = reader.GetInt32(4);
                nodes.Add(node);
            }
            reader.Close();
            cmd.Dispose();
            return(nodes);
        }
Пример #3
0
 public IActionResult OnPost(int?id, int?parentArticleId, int?currentArticleId)
 {
     if (id != null && parentArticleId != null && currentArticleId != null)
     {
         SuccesInfo = StringResources.StringResources.Instance.SuccesCreated;
         var node = new Models.TaxNode
         {
             Id = id.Value, ArticleId = currentArticleId.Value
         };
         node.Update(parentArticleId.Value);
     }
     else
     {
         WarningInfo = StringResources.StringResources.Instance.ErrorCreate;
     }
     return(RedirectToPage("./Index"));
 }
Пример #4
0
 public IActionResult OnGet(int id)
 {
     if (!HttpContext.Session.Keys.Contains("auid"))
     {
         return(RedirectToPage("/Auth/Login"));
     }
     TaxNode = Models.TaxNode.GetById(id);
     Article = Models.Article.GetById(TaxNode.ArticleId);
     if (TaxNode.ParentNodeId > 0)
     {
         var parent = Models.TaxNode.GetById(TaxNode.ParentNodeId);
         ParentArticle = Models.Article.GetById(parent.ArticleId);
     }
     if (TaxNode == null || Article == null)
     {
         return(RedirectToPage("./Index"));
     }
     return(Page());
 }
Пример #5
0
 public IActionResult OnPost(int?parentArticleId, int?currentArticleId)
 {
     if (parentArticleId != null && currentArticleId != null)
     {
         SuccesInfo = StringResources.StringResources.Instance.SuccesCreated;
         var node = new Models.TaxNode {
             ArticleId = currentArticleId.Value
         };
         try
         {
             node.Create(parentArticleId.Value);
         }
         catch (InfoException e)
         {
             SuccesInfo  = "";
             WarningInfo = e.Message;
         }
     }
     else
     {
         WarningInfo = StringResources.StringResources.Instance.ErrorCreate;
     }
     return(Page());
 }