liaoxujun@qq.com
2024-02-26 a71cfd93b85389e6473afdca1b7d6411bb676d0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using cy_scdz.Model.Set;
using Elsa.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using utils;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
 
namespace cy_scdz.ViewModel.Setting
{
    public partial class SettingVm:BaseCRUDVM<Dictionary>
    {
 
      public  List<Dictionary> allNodesWithChildren= new List<Dictionary>();
        public SettingVm()
        {
            SetInclude(x => x.Parent);
            
        }
 
        protected override void InitVM()
        {
            allNodesWithChildren = DC.Set<Dictionary>().Where(x=>x.Parent==null)
                .Include(x=>x.Children)    
      .ThenInclude(c => c.Children)
 
      .ToList();
        }
 
        public override void DoAdd()
        {
            base.DoAdd();
        }
        /// <summary>
        /// 增加一个新的字典
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="PKey">父建key</param>
        /// <param name="Key">自身key</param>
        /// <param name="value">值</param>
        public void addNew(string name, string? PKey=null,string? Key=null, string? value = null)
        {
            Dictionary Pd = null;
            if(!string.IsNullOrEmpty(PKey))
            {
                Pd= DC.Set<Dictionary>().Where(x => x.IsEn == true && x.Key == PKey).FirstOrDefault();
                if(Pd==null)
                {
                    MSD.AddModelError("ParentId", "没有找到上级信息");
                    return;
                }
                
            }
            Entity = new Dictionary()
            {
                Key = Key?? utilsFun.GenerateRandomString(10),
                Value = value,
                Name = name,
                IsEn = true,
                ParentId = Pd == null ? null : Pd.ID,
 
 
 
            };
            SetDuplicatedCheck();
            Validate();
            base.DoAdd();
            
 
 
 
        }
        public override void Validate()
        {
            base.Validate();
        }
        public override DuplicatedInfo<Dictionary> SetDuplicatedCheck()
        {
            var rv = CreateFieldsInfo(SimpleField(x => x.Name), SimpleField(x=>x.ParentId));
            rv.AddGroup(SimpleField(x => x.Key));
           
            return rv;
        }
   
        public override void DoEdit(bool updateAllFields = false)
        {
            base.DoEdit(updateAllFields);
        }
 
        public override void DoDelete()
        {
            base.DoDelete();
        }
 
 
  
 
     
      
      
     
      
    }
}