The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
This article extends the sample given in our documentation. The article depicts how all comments send their notifications while the comment is waiting to be approved. This however poses a problem - why do frontend users need to be notified that a comment has been posted while they are unable to see it before it is approved and published. Therefore this sample will extend the functionality such that Administrator users get notified then the commend is send for approval and all other users get a notification once the comment has been published.
Continuing from where the article leaves us we will need to only modify the implementation of the ICommentNotificationStrategy interface. First off we will need to modify the GetSubscriptionListKeys such that it returns an empty list of subscriber keys when the comment's status is marked as Waiting for Approval:
protected
override
IEnumerable<
string
> GetSubscriptionListKeys(ICommentEvent @
event
)
{
if
( @
event
.Item.Status == StatusConstants.WaitingForApproval)
{
return
new
List<
string
>();
}
else
{
return
base
.GetSubscriptionListKeys(@
event
);
}
}
Next we need to create a new list and populate it with admin users. This list will help us construct a new ISubscriberRequest list which will include all the comment subscribers for this notification. Since we want the comments to go to administrators only we filter the users based on their role and create a new SubscriberRequest for each user. All of this needs to be done in the GetDynamicSubscribers method.
protected
override
IEnumerable<ISubscriberRequest> GetDynamicSubscribers(ICommentEvent @
event
)
{
if
(@
event
.Item.Status == StatusConstants.WaitingForApproval)
{
var Admins =
new
List<ISubscriberRequest>();
List<User> users =
new
List<User>();
RoleManager roleMan = RoleManager.GetManager(SecurityManager.ApplicationRolesProviderName);
users = roleMan.GetUsersInRole(
"Administrators"
).ToList();
foreach
(var item
in
users)
{
var subscriberRequest =
new
SubscriberRequestProxy();
subscriberRequest.Email = item.Email;
subscriberRequest.FirstName = item.FirstName;
subscriberRequest.LastName = item.LastName;
subscriberRequest.ResolveKey = item.Id.ToString();
subscriberRequest.Disabled =
false
;
Admins.Add(subscriberRequest);
}
return
Admins;
}
else
{
return
null
;
}
At this point you are all set. You can find the complete code sample here.
View all posts from Ivan D.Dimitrov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.