public static void SetDeletionAuditProperties(object entityAsObj, int?userId)
        {
            if (entityAsObj is IHasDeletionTime)
            {
                IHasDeletionTime ihasDeletionTime = (IHasDeletionTime)ObjectExtensions.As <IHasDeletionTime>(entityAsObj);
                if (!ihasDeletionTime.DeletedDate.HasValue)
                {
                    ihasDeletionTime.DeletedDate = (new DateTime?(DateTime.Now));
                }
            }
            if (!(entityAsObj is IDeletionAudited))
            {
                return;
            }
            IDeletionAudited ideletionAudited = (IDeletionAudited)ObjectExtensions.As <IDeletionAudited>(entityAsObj);

            if (ideletionAudited.DeletedUserId.HasValue)
            {
                return;
            }
            if (!userId.HasValue)
            {
                ideletionAudited.DeletedUserId = (new int?());
            }
            else
            {
                ideletionAudited.DeletedUserId = (userId);
            }
        }
Exemplo n.º 2
0
 protected virtual void CancelDeletionForSoftDelete(EntityEntry entry)
 {
     if (!(entry.Entity is ISoftDelete))
     {
         return;
     }
     entry.Reload();
     entry.State = EntityState.Modified;
     ((ISoftDelete)ObjectExtensions.As <ISoftDelete>(entry.Entity)).IsDeleted = true;
 }
Exemplo n.º 3
0
 protected virtual void ApplyAbpConceptsForModifiedEntity(EntityEntry entry, int?userId, EntityChangeReport changeReport)
 {
     this.SetModificationAuditProperties(entry.Entity, userId);
     if (entry.Entity is ISoftDelete && ((ISoftDelete)ObjectExtensions.As <ISoftDelete>(entry.Entity)).IsDeleted)
     {
         this.SetDeletionAuditProperties(entry.Entity, userId);
         changeReport.ChangedEntities.Add(new EntityChangeEntry(entry.Entity, (EntityChangeType)2));
     }
     else
     {
         changeReport.ChangedEntities.Add(new EntityChangeEntry(entry.Entity, (EntityChangeType)1));
     }
 }
Exemplo n.º 4
0
        internal static T FindController <T>(string root) where T : IController
        {
            try
            {
                var controllers = new List <Type>();
                controllers.AddRange(Scanner.Scan <T>());

                foreach (var controller in controllers)
                {
                    var ctrl = (T)Activator.CreateInstance(controller);

                    if (ctrl != null && ctrl.Path.Equals(root))
                    {
                        return(ctrl);
                    }
                }
            }
            catch
            {
            }

            return(ObjectExtensions.As <T>(null));
        }