public static void AddUserRole(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, System.DateTime effDate, System.DateTime expDate, int userId, bool notifyUser)
        {
            RoleController objRoleController = new RoleController();
            UserRoleInfo   objUserRole       = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);

            Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
            objRoleController.AddUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID, effDate, expDate);
            objUser.RefreshRoles = true;
            UserController.UpdateUser(PortalSettings.PortalId, objUser);
            if (objUserRole == null)
            {
                objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_CREATED);
                if (notifyUser)
                {
                    SendNotification(objUser, objRole, PortalSettings, UserRoleActions.@add);
                }
            }
            else
            {
                objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_UPDATED);
                if (notifyUser)
                {
                    objUserRole = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                    SendNotification(objUser, objRole, PortalSettings, UserRoleActions.update);
                }
            }
        }
        private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
        {
            RoleController objRoles = new RoleController();
            ArrayList      Custom   = new ArrayList();

            Custom.Add(objRole.RoleName);
            Custom.Add(objRole.Description);
            switch (Action)
            {
            case UserRoleActions.add:
            case UserRoleActions.update:
                string preferredLocale = objUser.Profile.PreferredLocale;
                if (string.IsNullOrEmpty(preferredLocale))
                {
                    preferredLocale = PortalSettings.DefaultLanguage;
                }
                CultureInfo  ci          = new CultureInfo(preferredLocale);
                UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                if (Null.IsNull(objUserRole.EffectiveDate))
                {
                    Custom.Add(DateTime.Today.ToString("g", ci));
                }
                else
                {
                    Custom.Add(objUserRole.EffectiveDate.ToString("g", ci));
                }
                if (Null.IsNull(objUserRole.ExpiryDate))
                {
                    Custom.Add("-");
                }
                else
                {
                    Custom.Add(objUserRole.ExpiryDate.ToString("g", ci));
                }
                break;

            case UserRoleActions.delete:
                Custom.Add("");
                break;
            }
            Message _message = new Message();

            _message.FromUserID = PortalSettings.AdministratorId;
            _message.ToUserID   = objUser.UserID;
            _message.Subject    = Services.Localization.Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_SUBJECT", objUser);
            _message.Body       = Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_BODY", objUser, Services.Localization.Localization.GlobalResourceFile, Custom);
            _message.Status     = MessageStatusType.Unread;

            //_messagingController.SaveMessage(_message);
            //Services.Mail.Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
        }
 public static void AddUserRole(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, System.DateTime effDate, System.DateTime expDate, int userId, bool notifyUser)
 {
     RoleController objRoleController = new RoleController();
     UserRoleInfo objUserRole = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
     Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController();
     objRoleController.AddUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID, effDate, expDate);
     objUser.RefreshRoles = true;
     UserController.UpdateUser(PortalSettings.PortalId, objUser);
     if (objUserRole == null)
     {
         objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_CREATED);
         if (notifyUser)
         {
             SendNotification(objUser, objRole, PortalSettings, UserRoleActions.@add);
         }
     }
     else
     {
         objEventLog.AddLog("Role", objRole.RoleName, PortalSettings, userId, Services.Log.EventLog.EventLogController.EventLogType.USER_ROLE_UPDATED);
         if (notifyUser)
         {
             objUserRole = objRoleController.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
             SendNotification(objUser, objRole, PortalSettings, UserRoleActions.update);
         }
     }
 }
        private static void SendNotification(UserInfo objUser, RoleInfo objRole, PortalSettings PortalSettings, UserRoleActions Action)
        {
            RoleController objRoles = new RoleController();
            ArrayList Custom = new ArrayList();
            Custom.Add(objRole.RoleName);
            Custom.Add(objRole.Description);
            switch (Action)
            {
                case UserRoleActions.add:
                case UserRoleActions.update:
                    string preferredLocale = objUser.Profile.PreferredLocale;
                    if (string.IsNullOrEmpty(preferredLocale))
                    {
                        preferredLocale = PortalSettings.DefaultLanguage;
                    }
                    CultureInfo ci = new CultureInfo(preferredLocale);
                    UserRoleInfo objUserRole = objRoles.GetUserRole(PortalSettings.PortalId, objUser.UserID, objRole.RoleID);
                    if (Null.IsNull(objUserRole.EffectiveDate))
                    {
                        Custom.Add(DateTime.Today.ToString("g", ci));
                    }
                    else
                    {
                        Custom.Add(objUserRole.EffectiveDate.ToString("g", ci));
                    }
                    if (Null.IsNull(objUserRole.ExpiryDate))
                    {
                        Custom.Add("-");
                    }
                    else
                    {
                        Custom.Add(objUserRole.ExpiryDate.ToString("g", ci));
                    }
                    break;
                case UserRoleActions.delete:
                    Custom.Add("");
                    break;
            }
            Message _message = new Message();
            _message.FromUserID = PortalSettings.AdministratorId;
            _message.ToUserID = objUser.UserID;
            _message.Subject = Services.Localization.Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_SUBJECT", objUser);
            _message.Body = Localization.GetSystemMessage(objUser.Profile.PreferredLocale, PortalSettings, "EMAIL_ROLE_" + RoleController.UserRoleActionsCaption[(int)Action] + "_BODY", objUser, Services.Localization.Localization.GlobalResourceFile, Custom);
            _message.Status = MessageStatusType.Unread;

            //_messagingController.SaveMessage(_message);
            //Services.Mail.Mail.SendEmail(PortalSettings.Email, objUser.Email, _message.Subject, _message.Body);
        }