Example #1
0
        /// <summary>
        /// GetRolesByUserIdAsync
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="transContext"></param>
        /// <returns></returns>
        /// <exception cref="DatabaseException"></exception>
        /// <exception cref="CacheException"></exception>
        public Task <IEnumerable <Role> > GetRolesByUserIdAsync(long userId, TransactionContext?transContext = null)
        {
            return(TryCacheAsideAsync(CachedRolesByUserId.Key(userId), dbReader =>
            {
                var from = dbReader.From <Role>().RightJoin <RoleOfUser>((r, ru) => r.Id == ru.RoleId);
                var where = dbReader.Where <Role>().And <RoleOfUser>(ru => ru.UserId == userId);

                return dbReader.RetrieveAsync(from, where, transContext);
            }) !);
        }
Example #2
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="databaseReader"></param>
        /// <param name="cache"></param>
        /// <param name="memoryLockManager"></param>
        /// <exception cref="CacheException"></exception>
        public RoleOfUserRepo(ILogger <RoleOfUserRepo> logger, IDatabaseReader databaseReader, ICache cache, IMemoryLockManager memoryLockManager) : base(logger, databaseReader, cache, memoryLockManager)
        {
            _databaseReader = databaseReader;

            EntityAdded += (roleOfUser, args) =>
            {
                InvalidateCache(CachedRolesByUserId.Key(roleOfUser.UserId).Timestamp(args.UtcNowTicks));
                return(Task.CompletedTask);
            };

            EntityUpdated += (roleOfUser, args) =>
            {
                InvalidateCache(CachedRolesByUserId.Key(roleOfUser.UserId).Timestamp(args.UtcNowTicks));
                return(Task.CompletedTask);
            };

            EntityDeleted += (roleOfUser, args) =>
            {
                InvalidateCache(CachedRolesByUserId.Key(roleOfUser.UserId).Timestamp(args.UtcNowTicks));
                return(Task.CompletedTask);
            };
        }