Exemplo n.º 1
0
        internal override void BeforeStateChanged(Context context, EntityChangeState state)
        {
            // все поля должны ссылаться на меня
            if (state == EntityChangeState.Modify)
            {
                if (Properties.Any(p => p.ExcelImportRulePocoId != Id))
                {
                    var ex = Log.Exception(new Exception(@"Обновляемое правило импорта содержит недопустимые поля"));
#if DEBUG
                    throw ex;
#endif
                }
            }

            // записываем поля
            if (state == EntityChangeState.Add)
            {
                foreach (var prop in Properties)
                {
                    if (!prop.IsNew)
                    {
                        var ex = new Exception(@"Правило импорта записывается раньше собственных полей");
                        Log.Exception(ex);
#if DEBUG
                        throw ex;
#endif
                    }
                }
            }
        }
Exemplo n.º 2
0
 internal virtual void AfterStateChanged(Context context, EntityChangeState state)
 {
     if (state == EntityChangeState.Loaded)
     {
         _contextReference = new WeakReference(context);
     }
 }
Exemplo n.º 3
0
 internal override void BeforeStateChanged(Context context, EntityChangeState state)
 {
     if (state == EntityChangeState.Add)
     {
         Guid = Guid.NewGuid();
     }
 }
Exemplo n.º 4
0
        public void OnBeforeSetChanged(Entity entity, EntityChangeState state)
        {
            var handler = BeforeSetChanged;

            if (handler != null)
            {
                handler(this, new SetChangedEventArgument <Entity>()
                {
                    Entity = entity,
                    State  = state
                });
            }
        }
Exemplo n.º 5
0
        internal override void AfterStateChanged(Context context, EntityChangeState state)
        {
            // обновить поля
            if (state == EntityChangeState.Add)
            {
                foreach (var prop in Properties)
                {
                    prop.ExcelImportRulePocoId = Id;
                    context.ExcelImportRuleCell.AddOrAttach(prop);
                }

                context.SaveChanges();
            }

            // восстановить поля из базы
            if (state == EntityChangeState.Loaded)
            {
                _properties = context.ExcelImportRuleCell.Where(c => c.ExcelImportRulePocoId == Id).ToArray();
#if DEBUG
                if (_properties.Count() != CatalogItemSchema.Properties.Count())
                {
                    throw new Exception(@"В правиле импорта не хватает полей");
                }
#endif
            }

            // прибить поля тоже
            if (state == EntityChangeState.Delete)
            {
                if (Properties == null || Properties.Any(p => p.ExcelImportRulePocoId != Id))
                {
                    var ex = new Exception(@"Удаляемое правило импорта содержит некорректные поля");
                    Log.Exception(ex);
#if DEBUG
                    throw ex;
#endif
                }

                context.ExcelImportRuleCell.Remove(Properties);
                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 internal virtual void BeforeStateChanged(Context context, EntityChangeState state)
 {
 }
Exemplo n.º 7
0
 public static void SetChangeState(this RowInfo rowInfo, EntityChangeState changeState)
 {
     rowInfo._changeState = changeState;
 }