Example #1
0
        public static void Add(IAddOrGetEntityWithChanges <TEntity> msg)
        {
            try
            {
                using (var ctx = new TDBContext())
                {
                    TDBEntity entity;//
                    var       whereStr = msg.Changes.Aggregate("", (str, itm) => str + ($"{itm.Key} == \"{itm.Value}\" &&"));
                    whereStr = whereStr.TrimEnd('&');
                    if (string.IsNullOrEmpty(whereStr))
                    {
                        return;
                    }
                    entity = ctx.Set <TDBEntity>().Where(whereStr).FirstOrDefault();

                    if (entity != null)
                    {
                        EventMessageBus.Current.Publish(new EntityUpdated <TEntity>((TEntity)(object)entity, new StateEventInfo(msg.Process.Id, RevolutionData.Context.Entity.Events.EntityUpdated), msg.Process, Source), Source);
                        return;
                    }


                    entity = new TDBEntity();
                    ctx.Set <TDBEntity>().Add(entity);

                    entity.ApplyChanges(msg.Changes);

                    ctx.SaveChanges(true);
                    EventMessageBus.Current.Publish(new EntityUpdated <TEntity>((TEntity)(object)entity, new StateEventInfo(msg.Process.Id, RevolutionData.Context.Entity.Events.EntityUpdated), msg.Process, Source), Source);
                }
            }
            catch (Exception ex)
            {
                PublishProcesError(msg, ex, typeof(IEntityUpdated <TEntity>));
            }
        }
 public static void AddEntity <TEntity>(this IAddOrGetEntityWithChanges <TEntity> msg) where TEntity : class, IEntity
 {
     EF7DataContext <TEntity> .Add(msg);
 }
Example #3
0
 public static void Add(IAddOrGetEntityWithChanges <TEntity> msg)
 {
     typeof(EntityRepository <, ,>).MakeGenericType(typeof(TEntity), EntityType, ctxType)
     .GetMethod("Add")
     .Invoke(null, new object[] { msg });
 }