예제 #1
0
        public bool Merge(ParticipantGroup g)
        {
            if (!ContainsSimilar(g))
            {
                Items.Add(g);
                Items.Sort(new StdComparer());
                return(true);
            }

            return(false);
        }
예제 #2
0
        private void storeGroups()
        {
            // *** Delete removed one
            List <ParticipantGroup> toDelete = new List <ParticipantGroup>();

            foreach (var g2 in _dm.GetParticipantGroups())
            {
                ParticipantGroup g1 = null;
                _group2Group.TryGetValue(g2, out g1);
                if (g1 == null || GroupViewModel.Items.FirstOrDefault(i => i == g1) == null)
                {
                    toDelete.Add(g2);
                }
            }
            foreach (var g in toDelete)
            {
                _dm.GetParticipantGroups().Remove(g);
                _group2Group.Remove(g);
            }

            // *** Update & create new ones
            uint curSortPos = 1;

            foreach (var g1 in GroupViewModel.Items)
            {
                var found = _group2Group.FirstOrDefault(i => i.Value == g1);  // Find original
                var g2    = found.Key;
                g2 = _dm.GetParticipantGroups().FirstOrDefault(i => i == g2); // Check if already in DataModel

                if (g2 != null)
                { // Update existing one
                    g2.Name    = g1.Name;
                    g2.SortPos = curSortPos;
                }
                else
                { // Create new one
                    var gNew = new ParticipantGroup(null, g1.Name, curSortPos);
                    _dm.GetParticipantGroups().Add(gNew);
                    // Remove any old reference and replace with new one
                    if (found.Key != null)
                    {
                        _group2Group.Remove(found.Key);
                    }
                    _group2Group.Add(gNew, g1);
                }

                curSortPos++;
            }
        }
예제 #3
0
        private bool groupsDifferent()
        {
            // *** Check removed one
            foreach (var g2 in _dm.GetParticipantGroups())
            {
                ParticipantGroup g1 = null;
                _group2Group.TryGetValue(g2, out g1);
                if (g1 == null || GroupViewModel.Items.FirstOrDefault(i => i == g1) == null)
                {
                    return(true);
                }
            }

            // *** Check updated & new ones
            uint curSortPos = 1;

            foreach (var g1 in GroupViewModel.Items)
            {
                var found = _group2Group.FirstOrDefault(i => i.Value == g1);  // Find original
                var g2    = found.Key;
                g2 = _dm.GetParticipantGroups().FirstOrDefault(i => i == g2); // Check if already in DataModel

                if (g2 != null)
                { // Update existing one
                    if (g2.Name != g1.Name || g2.SortPos != curSortPos)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }

                curSortPos++;
            }

            return(false);
        }
예제 #4
0
        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);
                    }
                }
            }
        }
예제 #5
0
 public bool ContainsSimilar(ParticipantGroup g)
 {
     return(Items.FirstOrDefault(i => i.Name == g.Name) != null);
 }