Esempio n. 1
0
        public async Task <Result> AddSubscription(Subscription subscription)
        {
            var subscriptionDao = new DAO.Subscription(subscription);
            var mediaResult     = await _mediaDataStore.GetMedia(subscription.Media.MediaName);

            if (mediaResult.IsFailure)
            {
                _logger.LogError("Media {media} that should be subscribed to does not exist.", subscription.Media.MediaName);
                return(Result.Failure(
                           $"Media {subscription.Media.MediaName} that should be subscribed to does not exist."));
            }
            var notificationEndpointResult =
                await _notificationDataStore.GetNotificationEndpoint(subscription.NotificationEndpoint.Identifier);

            if (notificationEndpointResult.IsFailure)
            {
                _logger.LogError("NotificationEndpoint {endpoint} that should be used for the subscription to does not exist.", subscription.NotificationEndpoint.Identifier);
                return(Result.Failure(
                           $"NotificationEndpoint {subscription.NotificationEndpoint.Identifier} that should be used for the subscription to does not exist."));
            }

            subscriptionDao.Media = mediaResult.Value;
            subscriptionDao.NotificationEndpoint = notificationEndpointResult.Value;
            return(await _subscriptionDataStore.AddSubscription(subscriptionDao));
        }
Esempio n. 2
0
        public async Task <Result> AddSubscription(BusinessEntities.Subscription subscription, CancellationToken cancellationToken)
        {
            var mediaResult = await _mediaDataStore.GetMedia(subscription.Media.MediaName, cancellationToken);

            if (mediaResult.IsFailure)
            {
                _logger.LogError("Media {media} that should be subscribed to does not exist.", subscription.Media.MediaName);
                return(Result.Failure(
                           $"Media {subscription.Media.MediaName} that should be subscribed to does not exist."));
            }
            var notificationEndpointResult =
                await _notificationDataStore.GetNotificationEndpoint(subscription.NotificationEndpoint.Identifier, cancellationToken);

            if (notificationEndpointResult.IsFailure)
            {
                _logger.LogError("NotificationEndpoint {endpoint} that should be used for the subscription to does not exist.", subscription.NotificationEndpoint.Identifier);
                return(Result.Failure(
                           $"NotificationEndpoint {subscription.NotificationEndpoint.Identifier} that should be used for the subscription to does not exist."));
            }
            var subscriptionDao = new Subscription(mediaResult.Value, notificationEndpointResult.Value);

            return(await _subscriptionDataStore.AddSubscription(subscriptionDao, cancellationToken));
        }