Ejemplo n.º 1
0
        public static void ProcessChanges <T>(DbChangeStatus status, T arg, ObservableCollection <T> collection, TaskFactory sync)
        {
            Logger.Log.Info($"Изменения в объекте: {{object: {typeof(T)}, status: {status}}}");

            switch (status)
            {
            case DbChangeStatus.Add:
            case DbChangeStatus.Update:
                int index = collection.IndexOf(arg);
                if (index > -1)
                {
                    sync.StartNew(() =>
                    {
                        collection.RemoveAt(index);
                        collection.Insert(index, arg);
                    });
                }
                else
                {
                    sync.StartNew(() => collection.Add(arg));
                }
                break;

            case DbChangeStatus.Remove:
                if (collection.Contains(arg))
                {
                    sync.StartNew(() => collection.Remove(arg));
                }
                break;

            default:
                Logger.Log.Warn($"Необработанное событие изменения: {{type: {typeof(T)}, status: {status}}}");
                break;
            }
        }
Ejemplo n.º 2
0
        void ProcessChanges <T>(DbChangeStatus status, T arg, ObservableCollection <T> collection)
        {
            ProcessChangesHelper.ProcessChanges(status, arg, collection, sync);

            if (status == DbChangeStatus.Remove && arg is Staff staff)
            {
                Clear(Groups, x => x.CuratorId == staff.Id);
            }
        }
Ejemplo n.º 3
0
        private void Groups_OnChanged(DbChangeStatus status, Group group)
        {
            if (status != DbChangeStatus.Remove)
            {
                return;
            }

            if (selectedGroup.Id == group.Id)
            {
                sync.StartNew(() => GoBack());
            }
        }
Ejemplo n.º 4
0
        private void Students_OnChanged(DbChangeStatus status, Student student)
        {
            int index = Items.IndexOf(student);

            if (index > -1 && student.GroupId != Items[index].GroupId)
            {
                sync.StartNew(() => Items.Remove(student));
            }

            if (student.GroupId != selectedGroup.Id)
            {
                return;
            }

            ProcessChangesHelper.ProcessChanges(status, student, Items, sync);
        }
Ejemplo n.º 5
0
 private void Users_OnChanged(DbChangeStatus status, User arg)
 {
     ProcessChanges(status, arg, Users);
 }
Ejemplo n.º 6
0
 private void Staff_OnChanged(DbChangeStatus status, Staff arg)
 {
     ProcessChanges(status, arg, Staff);
 }
Ejemplo n.º 7
0
 private void Groups_OnChanged(DbChangeStatus status, Group arg)
 {
     ProcessChanges(status, arg, Groups);
 }