private void SubscriptionUpdated(object sender, MemberServices.SubscriptionUpdatedEventArgs e) { string message = Null.NullString; if (e.Cancel) { message = string.Format(Localization.GetString("UserUnSubscribed", LocalResourceFile), e.RoleName); } else { message = string.Format(Localization.GetString("UserSubscribed", LocalResourceFile), e.RoleName); } PortalSecurity.ClearRoles(); AddLocalizedModuleMessage(message, ModuleMessage.ModuleMessageType.GreenSuccess, true); }
protected void btnSubmit_Click(object sender, EventArgs e) { int id = GetId(); LoadQuiz(id); for (int i = 0; i < _quiz.Questions.Count; i++) { var question = _quiz.Questions[i]; var responses = new List <string>(Request.Form.GetValues("question" + i) ?? new string[] { }); if (responses.Count > 0) { for (int c = 0; c < question.Choices.Count; c++) { question.Choices[c].IsSelected = responses.Contains(question.Choices[c].Text); } } } _results = _quizService.ScoreQuiz(_quiz); pnlTakeQuiz.Visible = false; pnlQuizResults.Visible = true; if (!_quizService.CanUserTakeQuiz(id, _quiz)) { btnSubmitAgain.Visible = false; } var quizTakenActions = _results.Actions.Where(a => a.Condition == QuizCondition.QuizTaken); _quizService.LogQuiz(_quiz, ModuleId, id, quizTakenActions.FirstOrDefault() != null ? quizTakenActions.FirstOrDefault().Emails.FirstOrDefault().BodyTemplate : String.Empty); foreach (var a in quizTakenActions) { foreach (var email in a.Emails) { EmailService.SendEmail(email.From, email.To, email.Cc, email.Bcc, email.SubjectTemplate, email.BodyTemplate); } } if (_results.IsPassingScore) { var quizPassedActions = _results.Actions.Where(a => a.Condition == QuizCondition.QuizPassed); if (UserId != -1) { bool refreshUserRoles = false; foreach (var action in quizPassedActions) { foreach (var roleToAdd in action.UserRoles) { RoleController roleController = new RoleController(); var roleInfo = roleController.GetRoleByName(PortalId, roleToAdd.RoleName); if (roleInfo != null) { DateTime expireDate = roleToAdd.ExpiresAfterDays.HasValue ? DateTime.Now.AddDays(roleToAdd.ExpiresAfterDays.Value) : DotNetNuke.Common.Utilities.Null.NullDate; roleController.AddUserRole(PortalId, UserId, roleInfo.RoleID, expireDate); refreshUserRoles = true; } else { Exceptions.LogException( new ModuleLoadException("Tried to add user to non-existent role '" + roleToAdd.RoleName + "'")); } } } if (refreshUserRoles) { // Clear the user's cached/stored role membership, will reload on next page cycle PortalSecurity.ClearRoles(); DataCache.ClearUserCache(PortalId, UserInfo.Username); // Load the current roles into the user's current context, for use in this page cycle RoleController roleController = new RoleController(); UserInfo.Roles = roleController.GetRolesByUser(UserId, PortalId); } } } }