public void Import(AppDataModel srcModel) { var srcGroups = srcModel.GetParticipantGroups(); var srcClasses = srcModel.GetParticipantClasses(); var srcCategories = srcModel.GetParticipantCategories(); // TODO: only really added items are allowed to be in _x2x maps otherwise, class becomes inconsistent or points to a wrong group/category foreach (var g1 in srcGroups) { if (!GroupViewModel.ContainsSimilar(g1)) { ParticipantGroup g2 = null; if (!_group2Group.TryGetValue(g1, out g2)) { g2 = new ParticipantGroup(g1.Id, g1.Name, g1.SortPos); _group2Group.Add(g1, g2); GroupViewModel.Merge(g2); } else { System.Diagnostics.Debug.Assert(false); } } } foreach (var cat1 in srcCategories) { if (!CategoryViewModel.ContainsSimilar(cat1)) { ParticipantCategory cat2 = null; if (!_category2Category.TryGetValue(cat1, out cat2)) { cat2 = new ParticipantCategory(cat1.Name, cat1.PrettyName, cat1.SortPos, cat1.Synonyms); _category2Category.Add(cat1, cat2); CategoryViewModel.Merge(cat2); } else { System.Diagnostics.Debug.Assert(false); } } } foreach (var c1 in srcClasses) { if (!ClassViewModel.ContainsSimilar(c1)) { ParticipantClass c2 = null; if (!_class2Class.TryGetValue(c1, out c2)) { c2 = new ParticipantClass( c1.Id, c1.Group == null ? null : _group2Group[c1.Group], c1.Name, c1.Sex == null ? null : _category2Category[c1.Sex], c1.Year, c1.SortPos); _class2Class.Add(c1, c2); ClassViewModel.Merge(c2); } else { System.Diagnostics.Debug.Assert(false); } } } }