Пример #1
0
        public static void UpdateEntityViewWithChanges(IUpdateEntityViewWithChanges <TView> msg)
        {
            try
            {
                var exp = FindExpressionClass.FindExpression <TDbEntity, TDbView>();
                using (var ctx = new TDbContext())
                {
                    // ReSharper disable once ReplaceWithSingleCallToFirstOrDefault cuz EF7 bugging LEAVE JUST SO
                    TDbEntity res;//
                    if (msg.EntityId == 0)
                    {
                        res = new TDbEntity();
                        ctx.Set <TDbEntity>().Add(res);
                    }
                    else
                    {
                        res = ctx.Set <TDbEntity>().FirstOrDefault(x => x.Id == msg.EntityId);
                    }

                    res.ApplyChanges(msg.Changes);
                    ctx.SaveChanges(true);
                    //TODO: retrieve whole item
                    var ures = ctx.Set <TDbEntity>().Select(exp).FirstOrDefault(x => x.Id == res.Id);//
                    EventMessageBus.Current.Publish(new EntityViewWithChangesUpdated <TView>((TView)(object)ures, msg.Changes, new StateEventInfo(msg.Process.Id, EntityView.Events.EntityViewFound), msg.Process, Source), Source);
                }
            }
            catch (Exception ex)
            {
                PublishProcesError(msg, ex, typeof(IEntityViewWithChangesUpdated <TView>));
            }
        }
Пример #2
0
 public static void UpdateEntityViewWithChanges(IUpdateEntityViewWithChanges <TEntityView> msg)
 {
     typeof(EntityViewRepository <, , , ,>).MakeGenericType(typeof(TEntityView), ViewType, TEntity, EntityType, ctxType)
     .GetMethod("UpdateEntityViewWithChanges")
     .Invoke(null, new object[] { msg });
 }
Пример #3
0
 public static void UpdateEntityViewWithChanges <TEntityView>(this IUpdateEntityViewWithChanges <TEntityView> msg) where TEntityView : IEntityView
 {
     EntityViewDataContext <TEntityView> .UpdateEntityViewWithChanges(msg);
 }