public static ConfigurationFieldVM GetConfiguration(ConfigurationFieldVM racine, string fieldKey) { if (racine.Code == fieldKey) return racine; if (racine.Childs != null && racine.Childs.Count > 0) { foreach (var child in racine.Childs) { var conf = GetConfiguration(child, fieldKey); if (conf != null) return conf; } } return null; }
public static ConfigurationFieldVM LoadConfiguration(Guid idFirm, string fieldKey) { var config = GetConfigByFirm(idFirm, fieldKey); var racine = config.FirstOrDefault(x => x.ConfigurationField.Code == fieldKey); var model = new ConfigurationFieldVM { IdConfiguration = racine.IdConfiguration, IdField = racine.IdField.Value, Check = racine.Check.Value, Code = racine.ConfigurationField.Code, Label = racine.ConfigurationField.Label, Level = racine.ConfigurationField.Level.Value, }; Action<ConfigurationFieldVM, List<Data.Model.Configuration>> createModelTree = null; createModelTree = (x, y) => { if (x == null) return; var childs = y.Where(x1 => x1.ConfigurationField.IdFieldParent == x.IdField); if (childs != null && childs.Count() > 0) { x.Childs = new List<ConfigurationFieldVM>(); foreach (var child in childs) { var childvm = new ConfigurationFieldVM { IdConfiguration = child.IdConfiguration, IdField = child.IdField.Value, Check = child.Check.Value, Code = child.ConfigurationField.Code, Label = child.ConfigurationField.Label, Level = child.ConfigurationField.Level.Value, }; x.Childs.Add(childvm); createModelTree(childvm, config); } } }; createModelTree(model, config); return model; }