/// <summary> /// Check that subscription hash is valid and subscription didn't expire /// </summary> /// <param name="subGuid">Subscription GUID for subscriptions without</param> /// <param name="subscriptionHash">Subscription hash to check</param> /// <param name="requestTime">Date time of subscription request</param> /// <param name="checkOnly">Indicates if only check will be performed</param> private void CheckAndUnsubscribe(Guid subGuid, string subscriptionHash, string requestTime, bool checkOnly) { OptInApprovalResultEnum result = OptInApprovalResultEnum.NotFound; // Get date and time DateTime datetime = DateTimeHelper.ZERO_TIME; if (!string.IsNullOrEmpty(requestTime)) { try { datetime = DateTimeUrlFormatter.Parse(requestTime); } catch { DisplayError(GetString("general.unsubscription_unsuccessful")); return; } } if (subGuid != Guid.Empty) { if (SubscriptionObject != null) { if (!checkOnly) { ForumSubscriptionInfoProvider.DeleteForumSubscriptionInfo(SubscriptionObject); } result = OptInApprovalResultEnum.Success; } } // Check if subscription approval hash is supplied else if (!string.IsNullOrEmpty(subscriptionHash)) { result = checkOnly ? ForumSubscriptionInfoProvider.ValidateHash(SubscriptionObject, subscriptionHash, SiteContext.CurrentSiteName, datetime) : ForumSubscriptionInfoProvider.Unsubscribe(subscriptionHash, true, SiteContext.CurrentSiteName, datetime); } switch (result) { // Approving subscription was successful case OptInApprovalResultEnum.Success: if (!checkOnly) { ShowInfo(DataHelper.GetNotEmpty(SuccessfulUnsubscriptionText, GetString("Unsubscribe.Unsubscribed"))); } break; // Subscription was already approved case OptInApprovalResultEnum.Failed: DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_unsuccessful"))); break; case OptInApprovalResultEnum.TimeExceeded: DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_timeexceeded"))); break; // Subscription not found default: DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnsubscriptionText, GetString("general.unsubscription_NotSubscribed"))); break; } }