예제 #1
0
        public async Task <UserRole> AddRoleToUser(UserRole userRole)
        {
            await ValidateAddOrRemoveRole(userRole);

            UserRole existingUserRole = await new UserRoleLogic(Cache, Context).GetUserRole(userRole.RoleId, userRole.UserId);

            if (existingUserRole != null)
            {
                bool roleisExpired = existingUserRole.ExpiryDate == null ? false : existingUserRole.ExpiryDate < DateTime.UtcNow;

                userRole = await UpdateRole(existingUserRole, userRole);

                if (roleisExpired)
                {
                    //await SendRoleUpdatedEvent(userRole, true);
                }
            }
            else
            {
                userRole = await AddRole(userRole);

                //await SendRoleUpdatedEvent(userRole, true);
            }

            var userRoleCache = new UserRoleCache(Cache);

            await userRoleCache.InvalidateUserRoleCache(userRole.UserId);

            return(userRole);
        }
예제 #2
0
        private async Task RemoveRoleFromUser(UserRole userRole)
        {
            if (userRole == null)
            {
                return;
            }

            using (var uow = new UnitOfWork(Context))
            {
                var repo = new UserRoleRepository(uow);

                await repo.Delete(userRole.UserRoleId);
            }

            var userRoleCache = new UserRoleCache(Cache);

            await userRoleCache.InvalidateUserRoleCache(userRole.UserId);

            //await SendRoleUpdatedEvent(userRole, false);
        }