Пример #1
0
        public async Task <Unit> Handle(DeleteAllCommand request, CancellationToken cancellationToken)
        {
            var userId = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id;

            _notificationRepository.RemoveAllByUserId(userId);
            await _notificationRepository.UnitOfWork.SaveChangesAndDispatchDomainEventsAsync(cancellationToken);

            _notificationCache.Set(userId, new List <Notification>());

            return(await Unit.Task);
        }
Пример #2
0
        public async Task <Unit> Handle(DeleteSingleCommand request, CancellationToken cancellationToken)
        {
            var userId         = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id;
            var notificationId = Guid.Parse(request.NotificationId);

            await _notificationRepository.RemoveById(notificationId);

            var notifications = await _notificationCache.Get(userId);

            _notificationCache.Set(userId, notifications.Where(x => x.Id != notificationId));

            return(await Unit.Task);
        }
        public async Task <Unit> Handle(ReadAllCommand request, CancellationToken cancellationToken)
        {
            var userId = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id;
            await _notificationRepository.MarkAllAsRead(userId);

            var notifications = await _notificationCache.Get(userId);

            foreach (var notification in notifications)
            {
                notification.SetIsRead(true);
            }
            _notificationCache.Set(userId, notifications);

            return(await Unit.Task);
        }