コード例 #1
0
        public async Task <bool> SaveAsync(NotificationInput notificationInput, ModelStateDictionary modelState)
        {
            var result = await _notificationManager.SaveAsync(notificationInput, modelState);

            if (result && !notificationInput.NotificationId.HasValue)
            {
                var apiResultNotification = new ApiResultNotification
                {
                    Code    = 201,
                    Title   = notificationInput.Title,
                    Message = notificationInput.Message,
                };
                if (notificationInput.ToUserId.HasValue)
                {
                    var client = _hubContext.Clients.User(notificationInput.ToUserId.Value.ToString());
                    client.ReceiveMessage(apiResultNotification).ContinueWithOnFaultedHandleLog(_logger);
                }
                else
                {
                    _hubContext.Clients.All.ReceiveMessage(apiResultNotification).ContinueWithOnFaultedHandleLog(_logger);
                }
            }
            return(result);
        }
コード例 #2
0
        public async Task <bool> SaveAsync(NotificationInput notificationInput, ModelStateDictionary modelState)
        {
            var result = await _notificationRepository.SaveAsync(notificationInput, modelState);

            if (result && !notificationInput.NotificationId.HasValue)
            {
                var apiResultNotification = new ApiResultNotification
                {
                    Code    = 201,
                    Title   = notificationInput.Title,
                    Message = notificationInput.Message,
                };
                if (notificationInput.ToUserId.HasValue)
                {
                    var client = _hubContext.Clients.User(notificationInput.ToUserId.Value.ToString());
                    await client.ReceiveMessage(apiResultNotification);
                }
                else
                {
                    await _hubContext.Clients.All.ReceiveMessage(apiResultNotification);
                }
            }
            return(result);
        }