本文整理汇总了C#中DotNetNuke.Security.Roles.RoleController.GetUserRole方法的典型用法代码示例。如果您正苦于以下问题:C# RoleController.GetUserRole方法的具体用法?C# RoleController.GetUserRole怎么用?C# RoleController.GetUserRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetNuke.Security.Roles.RoleController
的用法示例。
在下文中一共展示了RoleController.GetUserRole方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteUserRoleInternal
private static bool DeleteUserRoleInternal(int portalId, int userId, int roleId)
{
var roleController = new RoleController();
var user = UserController.GetUserById(portalId, userId);
var userRole = roleController.GetUserRole(portalId, userId, roleId);
var portalController = new PortalController();
bool delete = true;
var portal = portalController.GetPortal(portalId);
if (portal != null && userRole != null)
{
if (CanRemoveUserFromRole(portal, userId, roleId))
{
provider.RemoveUserFromRole(portalId, user, userRole);
var objEventLog = new EventLogController();
objEventLog.AddLog(userRole, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.ROLE_UPDATED);
//Remove the UserInfo from the Cache, as it has been modified
DataCache.ClearUserCache(portalId, user.Username);
TestableRoleController.Instance.ClearRoleCache(portalId);
}
else
{
delete = false;
}
}
return delete;
}
示例2: AddGroupOwnerNotification
internal virtual Notification AddGroupOwnerNotification(string notificationTypeName, int tabId, int moduleId, RoleInfo group, UserInfo initiatingUser)
{
var notificationType = NotificationsController.Instance.GetNotificationType(notificationTypeName);
var tokenReplace = new GroupItemTokenReplace(group);
var subject = Localization.GetString(notificationTypeName + ".Subject", Constants.SharedResourcesPath);
var body = Localization.GetString(notificationTypeName + ".Body", Constants.SharedResourcesPath);
subject = subject.Replace("[DisplayName]", initiatingUser.DisplayName);
subject = subject.Replace("[ProfileUrl]", Globals.UserProfileURL(initiatingUser.UserID));
subject = tokenReplace.ReplaceGroupItemTokens(subject);
body = body.Replace("[DisplayName]", initiatingUser.DisplayName);
body = body.Replace("[ProfileUrl]", Globals.UserProfileURL(initiatingUser.UserID));
body = tokenReplace.ReplaceGroupItemTokens(body);
var roleCreator = UserController.GetUserById(group.PortalID, group.CreatedByUserID);
var roleOwners = new List<UserInfo>();
var rc = new RoleController();
foreach (UserInfo userInfo in rc.GetUsersByRoleName(group.PortalID, group.RoleName)) {
var userRoleInfo = rc.GetUserRole(group.PortalID, userInfo.UserID, group.RoleID);
if (userRoleInfo.IsOwner && userRoleInfo.UserID != group.CreatedByUserID)
{
roleOwners.Add(UserController.GetUserById(group.PortalID, userRoleInfo.UserID));
}
}
roleOwners.Add(roleCreator);
//Need to add from sender details
var notification = new Notification
{
NotificationTypeID = notificationType.NotificationTypeId,
Subject = subject,
Body = body,
IncludeDismissAction = true,
SenderUserID = initiatingUser.UserID,
Context = String.Format("{0}:{1}:{2}:{3}", tabId, moduleId, group.RoleID, initiatingUser.UserID)
};
NotificationsController.Instance.SendNotification(notification, initiatingUser.PortalID, null, roleOwners);
return notification;
}
示例3: ApproveMember
public HttpResponseMessage ApproveMember(NotificationDTO postData)
{
try
{
var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
if (recipient == null) return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to locate recipient");
var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
ParseKey(notification.Context);
if (_memberId <= 0)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to locate Member");
}
if (_roleInfo == null)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to locate Role");
}
var member = UserController.GetUserById(PortalSettings.PortalId, _memberId);
if (member != null)
{
var roleController = new RoleController();
var memberRoleInfo = roleController.GetUserRole(PortalSettings.PortalId, _memberId, _roleInfo.RoleID);
memberRoleInfo.Status = RoleStatus.Approved;
roleController.UpdateUserRole(PortalSettings.PortalId, _memberId, _roleInfo.RoleID, RoleStatus.Approved, false, false);
var notifications = new Notifications();
var groupOwner = UserController.GetUserById(PortalSettings.PortalId, _roleInfo.CreatedByUserID);
notifications.AddMemberNotification(Constants.MemberApprovedNotification, _tabId, _moduleId, _roleInfo, groupOwner, member);
NotificationsController.Instance.DeleteAllNotificationRecipients(postData.NotificationId);
return Request.CreateResponse(HttpStatusCode.OK, new {Result = "success"});
}
} catch (Exception exc)
{
Logger.Error(exc);
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
}
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unknown Error");
}
示例4: GetDates
/// -----------------------------------------------------------------------------
/// <summary>
/// GetDates gets the expiry/effective Dates of a Users Role membership
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="UserId">The Id of the User</param>
/// <param name="RoleId">The Id of the Role</param>
/// <history>
/// [cnurse] 9/10/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// [cnurse] 01/20/2006 Added support for Effective Date
/// </history>
/// -----------------------------------------------------------------------------
private void GetDates(int UserId, int RoleId)
{
DateTime? expiryDate = null;
DateTime? effectiveDate = null;
var objRoles = new RoleController();
UserRoleInfo objUserRole = objRoles.GetUserRole(PortalId, UserId, RoleId);
if (objUserRole != null)
{
if (Null.IsNull(objUserRole.EffectiveDate) == false)
{
effectiveDate = objUserRole.EffectiveDate;
}
if (Null.IsNull(objUserRole.ExpiryDate) == false)
{
expiryDate = objUserRole.ExpiryDate;
}
}
else //new role assignment
{
RoleInfo objRole = TestableRoleController.Instance.GetRole(PortalId, r => r.RoleID == RoleId);
if (objRole.BillingPeriod > 0)
{
switch (objRole.BillingFrequency)
{
case "D":
expiryDate = DateTime.Now.AddDays(objRole.BillingPeriod);
break;
case "W":
expiryDate = DateTime.Now.AddDays(objRole.BillingPeriod*7);
break;
case "M":
expiryDate = DateTime.Now.AddMonths(objRole.BillingPeriod);
break;
case "Y":
expiryDate = DateTime.Now.AddYears(objRole.BillingPeriod);
break;
}
}
}
effectiveDatePicker.SelectedDate = effectiveDate;
expiryDatePicker.SelectedDate = expiryDate;
}
示例5: ShowTrial
protected bool ShowTrial(int roleID)
{
var objRoles = new RoleController();
bool showTrial = Null.NullBoolean;
RoleInfo objRole = objRoles.GetRole(roleID, PortalSettings.PortalId);
if (objRole.TrialFrequency == "N" || (objRole.IsPublic && objRole.ServiceFee == 0.0))
{
showTrial = Null.NullBoolean;
}
else if (objRole.IsPublic && objRole.TrialFee == 0.0)
{
//Use Trial?
UserRoleInfo objUserRole = objRoles.GetUserRole(PortalId, UserInfo.UserID, roleID);
if ((objUserRole == null) || (!objUserRole.IsTrialUsed))
{
showTrial = true;
}
}
return showTrial;
}
示例6: AddUserRole
/// -----------------------------------------------------------------------------
/// <summary>
/// Adds a User to a Role
/// </summary>
/// <param name="user">The user to assign</param>
/// <param name="role">The role to add</param>
/// <param name="portalSettings">The PortalSettings of the Portal</param>
/// <param name="status">RoleStatus</param>
/// <param name="effectiveDate">The expiry Date of the Role membership</param>
/// <param name="expiryDate">The expiry Date of the Role membership</param>
/// <param name="notifyUser">A flag that indicates whether the user should be notified</param>
/// <param name="isOwner">A flag that indicates whether this user should be one of the group owners</param>
/// -----------------------------------------------------------------------------
public static void AddUserRole(UserInfo user, RoleInfo role, PortalSettings portalSettings, RoleStatus status, DateTime effectiveDate, DateTime expiryDate, bool notifyUser, bool isOwner)
{
var roleController = new RoleController();
var userRole = roleController.GetUserRole(portalSettings.PortalId, user.UserID, role.RoleID);
var eventLogController = new EventLogController();
//update assignment
roleController.AddUserRole(portalSettings.PortalId, user.UserID, role.RoleID, status, isOwner, effectiveDate, expiryDate);
UserController.UpdateUser(portalSettings.PortalId, user);
if (userRole == null)
{
eventLogController.AddLog("Role", role.RoleName, portalSettings, user.UserID, EventLogController.EventLogType.USER_ROLE_CREATED);
//send notification
if (notifyUser)
{
SendNotification(user, role, portalSettings, [email protected]);
}
}
else
{
eventLogController.AddLog("Role", role.RoleName, portalSettings, user.UserID, EventLogController.EventLogType.USER_ROLE_UPDATED);
if (notifyUser)
{
roleController.GetUserRole(portalSettings.PortalId, user.UserID, role.RoleID);
SendNotification(user, role, portalSettings, UserRoleActions.update);
}
}
//Remove the UserInfo from the Cache, as it has been modified
DataCache.ClearUserCache(portalSettings.PortalId, user.Username);
}
示例7: SendNotification
private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
{
var objRoles = new RoleController();
var Custom = new ArrayList {objRole.RoleName, objRole.Description};
switch (Action)
{
case UserRoleActions.add:
case UserRoleActions.update:
string preferredLocale = objUser.Profile.PreferredLocale;
if (string.IsNullOrEmpty(preferredLocale))
{
preferredLocale = PortalSettings.DefaultLanguage;
}
var ci = new CultureInfo(preferredLocale);
UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
Custom.Add(Null.IsNull(objUserRole.EffectiveDate)
? DateTime.Today.ToString("g", ci)
: objUserRole.EffectiveDate.ToString("g", ci));
Custom.Add(Null.IsNull(objUserRole.ExpiryDate) ? "-" : objUserRole.ExpiryDate.ToString("g", ci));
break;
case UserRoleActions.delete:
Custom.Add("");
break;
}
var _message = new Message
{
FromUserID = PortalSettings.AdministratorId,
ToUserID = objUser.UserID,
Subject =
Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings,
"EMAIL_ROLE_" +
UserRoleActionsCaption[(int) Action] +
"_SUBJECT", objUser),
Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale,
PortalSettings,
"EMAIL_ROLE_" +
UserRoleActionsCaption[(int) Action] + "_BODY",
objUser,
Localization.GlobalResourceFile,
Custom),
Status = MessageStatusType.Unread
};
//_messagingController.SaveMessage(_message);
Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
}
示例8: Recipients
/// <summary>All bulk mail recipients, derived from role names and individual adressees </summary>
/// <returns>List of userInfo objects, who receive the bulk mail </returns>
/// <remarks>user.Email used for sending, other properties might be used for TokenReplace</remarks>
public List<UserInfo> Recipients()
{
EnsureNotDisposed();
var userList = new List<UserInfo>();
var keyList = new List<string>();
var roleController = new RoleController();
foreach (string roleName in _addressedRoles)
{
string role = roleName;
var roleInfo = TestableRoleController.Instance.GetRole(_portalSettings.PortalId, r => r.RoleName == role);
foreach (UserInfo objUser in roleController.GetUsersByRoleName(_portalSettings.PortalId, roleName))
{
UserInfo user = objUser;
ProfileController.GetUserProfile(ref user);
var userRole = roleController.GetUserRole(_portalSettings.PortalId, objUser.UserID, roleInfo.RoleID);
//only add if user role has not expired and effectivedate has been passed
if ((userRole.EffectiveDate <= DateTime.Now || Null.IsNull(userRole.EffectiveDate)) && (userRole.ExpiryDate >= DateTime.Now || Null.IsNull(userRole.ExpiryDate)))
{
ConditionallyAddUser(objUser, ref keyList, ref userList);
}
}
}
foreach (UserInfo objUser in _addressedUsers)
{
ConditionallyAddUser(objUser, ref keyList, ref userList);
}
return userList;
}
示例9: SendNotification
/// <summary>
/// SendNotification sends an email notification to the user of the change in his/her role
/// </summary>
/// <param name="userId">The Id of the User</param>
/// <param name="roleId">The Id of the Role</param>
/// <param name="action"></param>
/// <history>
/// [cnurse] 9/10/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
private void SendNotification( int userId, int roleId, string action )
{
UserInfo objUser = UserController.GetUser( PortalId, userId, false );
RoleController objRoles = new RoleController();
RoleInfo objRole = objRoles.GetRole( roleId, PortalId );
ArrayList Custom = new ArrayList();
Custom.Add( objRole.RoleName );
Custom.Add( objRole.Description );
switch( action )
{
case "add":
UserRoleInfo objUserRole = objRoles.GetUserRole( PortalId, userId, roleId );
Custom.Add( objUserRole.EffectiveDate.ToString() );
Custom.Add( objUserRole.ExpiryDate.ToString() );
Mail.SendMail( PortalSettings.Email, objUser.Email, "", Localization.GetSystemMessage( objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_ASSIGNMENT_SUBJECT", objUser ), Localization.GetSystemMessage( objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_ASSIGNMENT_BODY", objUser, Localization.GlobalResourceFile, Custom ), "", "", "", "", "", "" );
break;
case "remove":
Custom.Add( "" );
Mail.SendMail( PortalSettings.Email, objUser.Email, "", Localization.GetSystemMessage( objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_UNASSIGNMENT_SUBJECT", objUser ), Localization.GetSystemMessage( objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_UNASSIGNMENT_BODY", objUser, Localization.GlobalResourceFile, Custom ), "", "", "", "", "", "" );
break;
}
}
示例10: GetDates
/// <summary>
/// GetDates gets the expiry/effective Dates of a Users Role membership
/// </summary>
/// <param name="userId">The Id of the User</param>
/// <param name="roleId">The Id of the Role</param>
/// <history>
/// [cnurse] 9/10/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// [cnurse] 01/20/2006 Added support for Effective Date
/// </history>
private void GetDates( int userId, int roleId )
{
string strExpiryDate = "";
string strEffectiveDate = "";
RoleController objRoles = new RoleController();
UserRoleInfo objUserRole = objRoles.GetUserRole( PortalId, userId, roleId );
if( objUserRole != null )
{
if( Null.IsNull( objUserRole.EffectiveDate ) == false )
{
strEffectiveDate = objUserRole.EffectiveDate.ToShortDateString();
}
if( Null.IsNull( objUserRole.ExpiryDate ) == false )
{
strExpiryDate = objUserRole.ExpiryDate.ToShortDateString();
}
}
else // new role assignment
{
RoleInfo objRole = objRoles.GetRole( roleId, PortalId );
if( objRole.BillingPeriod > 0 )
{
switch( objRole.BillingFrequency )
{
case "D":
strExpiryDate = DateTime.Now.AddDays(objRole.BillingPeriod).ToShortDateString();
break;
case "W":
strExpiryDate = DateTime.Now.AddDays(objRole.BillingPeriod * 7).ToShortDateString();
break;
case "M":
strExpiryDate = DateTime.Now.AddMonths(objRole.BillingPeriod).ToShortDateString();
break;
case "Y":
strExpiryDate = DateTime.Now.AddYears(objRole.BillingPeriod).ToShortDateString();
break;
}
}
}
txtEffectiveDate.Text = strEffectiveDate;
txtExpiryDate.Text = strExpiryDate;
}
示例11: ApproveMember
public ActionResult ApproveMember(int notificationId)
{
try
{
var recipient = InternalMessagingController.Instance.GetMessageRecipient(notificationId, UserInfo.UserID);
if (recipient == null) return Json(new { Result = "error" });
var notification = NotificationsController.Instance.GetNotification(notificationId);
ParseKey(notification.Context);
if (MemberId <= 0) return Json(new { Result = "error" });
if (roleInfo == null) return Json(new { Result = "error" });
var member = UserController.GetUserById(PortalSettings.PortalId, MemberId);
if (member != null)
{
var roleController = new RoleController();
var memberRoleInfo = roleController.GetUserRole(PortalSettings.PortalId, MemberId, roleInfo.RoleID);
memberRoleInfo.Status = RoleStatus.Approved;
roleController.UpdateUserRole(PortalSettings.PortalId, MemberId, roleInfo.RoleID, RoleStatus.Approved, false, false);
var notifications = new Notifications();
var groupOwner = UserController.GetUserById(PortalSettings.PortalId, roleInfo.CreatedByUserID);
notifications.AddMemberNotification(Constants.MemberApprovedNotification, TabId, ModuleId, roleInfo, groupOwner, member);
NotificationsController.Instance.DeleteAllNotificationRecipients(notificationId);
return Json(new { Result = "success" });
}
} catch (Exception exc)
{
DnnLog.Error(exc);
}
return Json(new { Result = "error" });
}