Esempio n. 1
0
        /// <summary>
        /// Subscribes the user specified to the thread specified for notifications. A transaction can be specified to save the information inside the
        /// transaction specified. If the user is already subscribed to this thread, nothing is done
        /// </summary>
        /// <param name="threadId">The thread ID.</param>
        /// <param name="userId">The user ID.</param>
        /// <param name="adapter">The live adapter with an active transaction. Can be null, in which case a local adapter is used.</param>
        /// <returns></returns>
        public static async Task <bool> AddThreadToSubscriptionsAsync(int threadId, int userId, IDataAccessAdapter adapter)
        {
            var localAdapter = adapter == null;
            var adapterToUse = adapter ?? new DataAccessAdapter();

            try
            {
                // check if this user is already subscribed to this thread. If not, add a new subscription.
                if (await ThreadGuiHelper.GetThreadSubscriptionAsync(threadId, userId, adapterToUse) == null)
                {
                    // user isn't yet subscribed, add the subscription
                    return(await adapterToUse.SaveEntityAsync(new ThreadSubscriptionEntity { UserID = userId, ThreadID = threadId }).ConfigureAwait(false));
                }

                // already subscribed, no-op.
                return(true);
            }
            finally
            {
                if (localAdapter)
                {
                    adapterToUse.Dispose();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Unsubscribes the specified user from the specified thread.
        /// </summary>
        /// <param name="threadId">The thread ID.</param>
        /// <param name="userId">The user ID.</param>
        /// <returns>true if delete succeeded, false otherwise</returns>
        public static async Task <bool> RemoveSingleSubscriptionAsync(int threadId, int userId)
        {
            var subscription = await ThreadGuiHelper.GetThreadSubscriptionAsync(threadId, userId);

            if (subscription != null)
            {
                // there's a subscription, delete it
                using (var adapter = new DataAccessAdapter())
                {
                    return(await adapter.DeleteEntityAsync(subscription).ConfigureAwait(false));
                }
            }

            return(true);
        }
Esempio n. 3
0
 /// <summary>
 /// Checks if thread is already subscribed. If so, true is returned otherwise false.
 /// </summary>
 /// <param name="userId">The user ID.</param>
 /// <param name="threadId">The thread ID.</param>
 /// <returns>true if the user is already subscribed to this thread otherwise false</returns>
 public static async Task <bool> CheckIfThreadIsAlreadySubscribedAsync(int userId, int threadId)
 {
     return(await ThreadGuiHelper.GetThreadSubscriptionAsync(threadId, userId) != null);
 }