@@ -18,10 +18,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
18
*/
19
19
20
20
using DotNetNuke . Framework . JavaScriptLibraries ;
21
+ using DotNetNuke . Security . Roles ;
21
22
using DotNetNuke . Services . Localization ;
22
23
using DotNetNuke . Web . Mvc . Framework . ActionFilters ;
23
24
using DotNetNuke . Web . Mvc . Framework . Controllers ;
24
- using System . Collections . Generic ;
25
25
using System . Web . Mvc ;
26
26
using Upendo . Modules . UserManager . Utility ;
27
27
using Upendo . Modules . UserManager . ViewModels ;
@@ -32,6 +32,7 @@ namespace Upendo.Modules.UserManager.Controllers
32
32
public class RolesManageController : DnnController
33
33
{
34
34
private readonly string ResourceFile = "~/DesktopModules/MVC/Upendo.Modules.UserManager/App_LocalResources/UserManageController.resx" ;
35
+ private readonly string RolesResourceFile = "~/DesktopModules/MVC/Upendo.Modules.UserManager/App_LocalResources/RolesManageController.resx" ;
35
36
36
37
public RolesManageController ( )
37
38
{
@@ -77,6 +78,18 @@ public ActionResult Create()
77
78
[ HttpPost ]
78
79
public ActionResult Create ( RolesViewModel item )
79
80
{
81
+ // Check if the RoleName is already in use
82
+ var portalId = ModuleContext . PortalId ;
83
+ var rol = RoleController . Instance . GetRoleByName ( portalId , item . RoleName ) ;
84
+ if ( rol != null )
85
+ {
86
+ ViewBag . RoleGroups = RolesRepository . GetRoleGroups ( portalId ) ;
87
+ ViewBag . StatusList = RolesRepository . StatusList ( ) ;
88
+ ViewBag . ErrorMessage = Localization . GetString ( "RoleNameExists.Text" , RolesResourceFile ) ;
89
+ return View ( item ) ;
90
+ }
91
+
92
+ // If no validation issue, create the role
80
93
RolesRepository . CreateRol ( item ) ;
81
94
return RedirectToAction ( "Index" ) ;
82
95
}
@@ -93,6 +106,19 @@ public ActionResult Edit(int itemId)
93
106
[ HttpPost ]
94
107
public ActionResult Edit ( RolesViewModel item )
95
108
{
109
+ // Check if the name has changed and if the new name is already in use
110
+ var portalId = ModuleContext . PortalId ;
111
+ var originalRole = RoleController . Instance . GetRoleById ( portalId , item . RoleId ) ;
112
+ var existingRole = RoleController . Instance . GetRoleByName ( portalId , item . RoleName ) ;
113
+ if ( originalRole != null && originalRole . RoleName != item . RoleName && existingRole != null )
114
+ {
115
+ ViewBag . RoleGroups = RolesRepository . GetRoleGroups ( portalId ) ;
116
+ ViewBag . StatusList = RolesRepository . StatusList ( ) ;
117
+ ViewBag . ErrorMessage = Localization . GetString ( "RoleNameExists.Text" , RolesResourceFile ) ;
118
+ return View ( item ) ;
119
+ }
120
+
121
+ // If no validation issue, proceed with editing the role
96
122
RolesRepository . EditRol ( item ) ;
97
123
return RedirectToAction ( "Index" ) ;
98
124
}
@@ -111,4 +137,4 @@ public ActionResult Delete(int itemId)
111
137
return RedirectToAction ( "Index" ) ;
112
138
}
113
139
}
114
- }
140
+ }
0 commit comments