+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Post Processing Hook to set Subscription Timeout?

Post Processing Hook to set Subscription Timeout?

2 posts, 0 answered
  1. RickC
    RickC avatar
    24 posts
    Registered:
    23 Apr 2003
    07 Mar 2012
    Link to this post
    My Ecommerce application is to provide access to Private Sitefinity Blog Content for a period of a year, just like a magazine subscription.

    I have Ecommerce working to grant the user the correct Role Permissions after their purchase but I need a method of having their Role expire 365 days from the date of purchase.
  2. Venkata Koppaka
    Venkata Koppaka avatar
    67 posts
    Registered:
    24 Sep 2012
    12 Mar 2012
    Link to this post
    Hello Rick,

    You can use any .Net based Job Scheduler for doing this task. For this example I am using Quartz.net . You can add it to your project by using Nuget (http://nuget.org/packages/Quartz/1.0.3 )

    Then add this below code to your application. Please feel free to change the code below according to your needs.
    using System;
    using System.Linq;
    using Quartz;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Abstractions;
     
    namespace SitefinityWebApp
    {
        public class HourlyJob : IJob
        {
            public HourlyJob()
            {
            }
     
            public static void ScheduleJob(IScheduler sc)
            {
                JobDetail job = new JobDetail("HourlyJob", "ExecuteTask", typeof(HourlyJob));
                sc.ScheduleJob(job, TriggerUtils.MakeHourlyTrigger("HourlyTrigger"));
                sc.Start();
            }
     
            public void Execute(JobExecutionContext context)
            {
                try
                {
                    Guid roleId = Guid.NewGuid(); //Id of the role you want to remove the user from.
                    RoleManager roleManager = RoleManager.GetManager();
                    UserManager userManager = UserManager.GetManager();
     
                    var role = roleManager.GetRole(roleId);
                    var users = userManager.GetUsers();
                    foreach (var user in users)
                    {
                        if (roleManager.IsUserInRole(user.Id, role.Id) && MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(user.Id,role.Id))
                        {
                            roleManager.RemoveUserFromRole(user.Id, role);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Write(ex);
                }
            }
     
            private bool MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(Guid userId, Guid roleId)
            {
                //Add your custom logic here
                return true;
            }
        }
    }

    and in Global.asax in your Application_Start method, register the Job using the snippet below.
    protected void Application_Start(object sender, EventArgs e)
    {
        HourlyJob.ScheduleJob(new StdSchedulerFactory().GetScheduler());
    }

    Let us know if need further assistance.

    Greetings,
    Venkata Koppaka
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered