コード例 #1
0
        public ActionResult SaveRoleGroup(RoleGroupDto roleGroupDto)
        {
            ActionResult actionResult         = new ActionResult();
            Dictionary <string, dynamic> data = new Dictionary <string, dynamic>();

            try
            {
                Validate(roleGroupDto);

                RoleGroupInfo roleGroup = roleGroupDto.ToRoleGroupInfo();
                roleGroup.PortalID = PortalSettings.ActiveTab.PortalID;
                string Message = string.Empty;

                if (roleGroup.RoleGroupID < Null.NullInteger)
                {
                    try
                    {
                        DotNetNuke.Security.Roles.RoleController.AddRoleGroup(roleGroup);
                    }
                    catch (Exception ex)
                    {
                        actionResult.Errors.Add("DuplicateRoleGroup", ex);
                        actionResult.Message = Localization.GetString("DuplicateRoleGroup", Constants.LocalResourcesFile);
                    }
                }
                else
                {
                    try
                    {
                        DotNetNuke.Security.Roles.RoleController.UpdateRoleGroup(roleGroup);
                    }
                    catch (Exception ex)
                    {
                        actionResult.Errors.Add("DuplicateRoleGroup", ex);
                        actionResult.Message = Localization.GetString("DuplicateRoleGroup", Constants.LocalResourcesFile);
                    }
                }
                roleGroup = DotNetNuke.Security.Roles.RoleController.GetRoleGroups(PortalSettings.PortalId).Cast <RoleGroupInfo>()
                            .FirstOrDefault(r => r.RoleGroupName == roleGroupDto.Name?.Trim());

                data["FromRoleGroupInfo"] = RoleGroupDto.FromRoleGroupInfo(roleGroup);
                data["AllRoleGroup"]      = RoleGroupManager.GetRoleGroup(PortalSettings.PortalId);
                actionResult.Data         = data;
            }
            catch (Exception ex)
            {
                actionResult.AddError("SaveRoleGroup", ex.Message);
            }
            return(actionResult);
        }
コード例 #2
0
        public HttpResponseMessage SaveRoleGroup(RoleGroupDto roleGroupDto)
        {
            try
            {
                Validate(roleGroupDto);

                var roleGroup = roleGroupDto.ToRoleGroupInfo();
                roleGroup.PortalID = PortalId;

                if (roleGroup.RoleGroupID < Null.NullInteger)
                {
                    try
                    {
                        RoleController.AddRoleGroup(roleGroup);
                    }
                    catch
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                           Localization.GetString("DuplicateRoleGroup", Components.Constants.LocalResourcesFile)));
                    }
                }
                else
                {
                    try
                    {
                        RoleController.UpdateRoleGroup(roleGroup);
                    }
                    catch
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                           Localization.GetString("DuplicateRoleGroup", Components.Constants.LocalResourcesFile)));
                    }
                }

                roleGroup = RoleController.GetRoleGroups(PortalId).Cast <RoleGroupInfo>()
                            .FirstOrDefault(r => r.RoleGroupName == roleGroupDto.Name?.Trim());

                return(Request.CreateResponse(HttpStatusCode.OK, RoleGroupDto.FromRoleGroupInfo(roleGroup)));
            }
            catch (ArgumentException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #3
0
 private RoleGroupDto GetGroup(int groupId)
 {
     return(RoleGroupDto.FromRoleGroupInfo(DotNetNuke.Security.Roles.RoleController.GetRoleGroup(PortalSettings.ActiveTab.PortalID, groupId)));
 }