protected void AddRoleAction(int role_id, int scope_id, qPtl_User user)
    {
        var role_actions = qPtl_RoleAction.GetAvailableRoleActionsByRole(role_id, scope_id);
        DateTime startTime = DateTime.Now;
        DateTime endTime = DateTime.Now;

        foreach (var a in role_actions)
        {
            qPtl_UserAction action = new qPtl_UserAction();
            qPtl_Action act = new qPtl_Action(a.ActionID);
            action.ScopeID = scope_id;
            action.Available = "Yes";
            action.Created = DateTime.Now;
            action.CreatedBy = user.UserID;
            action.LastModified = DateTime.Now;
            action.LastModifiedBy = user.UserID;
            action.MarkAsDelete = 0;
            action.UserID = user.UserID;
            action.ActionID = a.ActionID;
            startTime = startTime.AddDays(a.StartDaysFromNow);
            endTime = endTime.AddDays(a.EndDaysFromNow);
            action.AvailableFrom = startTime;
            action.AvailableTo = endTime;
            action.AfterNumLogins = a.AfterNumLogins;
            action.Priority = a.Priority;
            action.SkipAllowed = a.SkipAllowed;
            action.NumberSkipsAllowed = a.NumberSkipsAllowed;
            action.Required = a.Required;
            action.OptionalOptOut = a.OptionOptOut;
            action.RedirectSkipURL = a.RedirectSkipURL;
            action.RedirectURL = a.RedirectURL;
            action.ReferenceID = act.ReferenceID;
            action.Insert();
        }
    }
    protected void btnAgreeRules_Click(object sender, EventArgs e)
    {
        int user_id = Convert.ToInt32(Context.Items["UserID"]);
        qPtl_UserProfile profile = new qPtl_UserProfile(user_id);
        profile.AgreeRules = DateTime.Now;
        profile.Update();

        // see if this is the action page -- if so, update actionID
        int action_id = 0;
        if (!String.IsNullOrEmpty(Convert.ToString(Request.QueryString["actionID"])))
        {
            action_id = Convert.ToInt32(Request.QueryString["actionID"]);
            qPtl_UserAction action = new qPtl_UserAction(user_id, action_id);
            action.LastModified = DateTime.Now;
            action.LastModifiedBy = user_id;
            action.UserCompleted = DateTime.Now;
            action.Update();

            Response.Redirect(action.RedirectURL);
        }
    }
        public static qPtl_UserAction GetActionByUserAndAction(Int32 user_id, int action_id)
        {
            var action = new qPtl_UserAction();

            action.container.Select(
                new DbQuery
                {
                    Where = "UserID = @UserID AND ActionID = @ActionID",
                    Parameters = new SqlQueryParameter[] { new SqlQueryParameter("@ActionID", action_id), new SqlQueryParameter("@UserID", user_id) }
                });

            return action.UserActionID > 0 ? action : null;
        }