Base solution for your next web application

Activities of "tom.ohle"

Answer

ok thanks that does look like what we've been looking for

Hi maliming,

Thanks for the quick response! I have couple of questions though.

  • Why is a new 1 year token created every time the admin user logs in? Why are the old 1 year tokens not deleted automatically when the admin user logs in?

  • Is this the definition of the UserTokenExpirationWorker? It appears to only delete tokens that have expired. Am I missing something that explains how the 1 year tokens are supposed to be cleaned up?

The project has been built upon the "<PROJECTNAME>-aspnetzero-7.3.1" ZIP archive and is still using EF Core 2.2.6.

I was able to successfully implement the following solution. Do you see any red flags?

src\aspnet-core\src\Company.App.EntityFrameworkCore\EntityFrameworkCore\AppDbContext.cs

namespace Company.App.EntityFrameworkCore
{
    public class AppDbContext : AbpZeroDbContext<Tenant, Role, User, AppDbContext>, IAbpPersistedGrantDbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
        {
            ChangeTracker.StateChanged += OnEntityStateChanged;
        }

        private void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
        {
            if (e.Entry.Entity is UserRole && e.NewState == EntityState.Deleted)
            {
                e.Entry.State = EntityState.Modified;
                e.Entry.CurrentValues["IsDeleted"] = true;
                e.Entry.CurrentValues["DeletionTime"] = DateTime.Now;
                e.Entry.CurrentValues["DeleterUserId"] = AbpSession.UserId;
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<UserRole>().HasQueryFilter(p => !EF.Property<bool>(p, "IsDeleted"));
            modelBuilder.Entity<UserRole>().Property<bool>("IsDeleted");
            modelBuilder.Entity<UserRole>().Property<DateTime?>("DeletionTime").IsRequired(false);
            modelBuilder.Entity<UserRole>().Property<long?>("DeleterUserId").IsRequired(false);
        }
    }
}

Hi @ismcagdas,

Yes. When I uncheck a role from the Roles tab in the User Edit modal neither the EntityDeleted or EntityDeleting event handlers are called.

However, the EntityUpdated event is triggered, but I have some concerns about using this event to detect deletions (see my original post).

Hi maliming,

The project has been built upon the "<PROJECTNAME>-aspnetzero-7.3.1" ZIP archive and is still using EF Core 2.2.6.

~~Also, I couldn't find a way to get the user behind any of the entity events. Is this even possible?~~

~~I found out I can inject AbpSession to get the current user.~~

Turns out AbpSession is already part of the base class.

Hi ismcagdas,

That totally worked. Thanks!

OK I got it working by deleting the github account from the license management and re-adding it.

Yes our accounts are already added. So far we've tried the sjlombardi-stantec and hhoang-stantec accounts. Something must be wrong with permissions on your side.

Please if you do not mind I'd appreciate it if you could delete 'WIP_Write_Off' and leave 'Stantec.WIP_Write_Off'

That is really good to know how the naming system works against the project count.

Thanks,

Tom.

Showing 11 to 20 of 27 entries