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 { public List allNodesWithChildren= new List(); public SettingVm() { SetInclude(x => x.Parent); } protected override void InitVM() { allNodesWithChildren = DC.Set().Where(x=>x.Parent==null) .Include(x=>x.Children) .ThenInclude(c => c.Children) .ToList(); } public override void DoAdd() { base.DoAdd(); } /// /// 增加一个新的字典 /// /// 名称 /// 父建key /// 自身key /// 值 public void addNew(string name, string? PKey=null,string? Key=null, string? value = null) { Dictionary Pd = null; if(!string.IsNullOrEmpty(PKey)) { Pd= DC.Set().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 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(); } } }