public ActionResult UserGroupRolesIndex() { UserGroupRolesModel model = new UserGroupRolesModel(); UserGroupServiceReference.UserGroupServiceClient UGClient = null; try { string usergroupid = ""; if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"])) { UGClient = new UserGroupServiceClient(); usergroupid = Request.QueryString["usergroupid"]; UserGroupDto Usergroupdto = UGClient.GetById(Convert.ToInt32(usergroupid)); UGClient.Close(); model.UserGroupName = Usergroupdto.UserGroupName; model.RoleGroupList = GetRoleGroupList(usergroupid); } string usertype = ""; if (!string.IsNullOrEmpty(Request.QueryString["userType"])) { usertype = Request.QueryString["userType"]; } } catch (Exception ex) { return(View("ErrorPage")); } return(View("UserGroupRoles", model)); }
public List <RoleModel> GetRoles(string roleGroup, string userGroupid) { List <RoleModel> roleModelList = new List <RoleModel>(); if (Session[roleGroup + userGroupid] == null) { Query query = new Query(); IList <RoleDto> Roles = new List <RoleDto>(); client = new RoleServiceClient(); UserGroupServiceReference.UserGroupServiceClient UGClient = null; UserGroupDto userGroupDto = new UserGroupDto(); UGClient = new UserGroupServiceReference.UserGroupServiceClient(); userGroupDto = UGClient.GetById(Convert.ToInt32(userGroupid)); if (!string.IsNullOrEmpty(Request.QueryString["userType"])) { string usertype = Request.QueryString["userType"]; if (usertype == "CAUser") { Criterion CriteriaIsApplicableForAckUsers = new Criterion("IsApplicableForAckUsers", false, CriteriaOperator.Equal); query.Add(CriteriaIsApplicableForAckUsers); } } Criterion CriteriaRoleGroup = new Criterion("RoleGroup", roleGroup, CriteriaOperator.Equal); query.Add(CriteriaRoleGroup); Roles = client.FindByQuery(query).Entities.ToList(); int RolePermissionId = 0; bool allowAdd, allowEdit, allowView, allowPrint, allowDelete; foreach (RoleDto role in Roles) { allowAdd = allowEdit = allowView = allowPrint = allowDelete = false; var ugrolelist = userGroupDto.RolePermissionsInUserGroup.Where(x => x.PermissionForRole.RoleId == role.RoleId); UserGroupRolePermissionDto urpDto = null; if (ugrolelist.Count() != 0) { urpDto = ugrolelist.First(); } if (urpDto != null) { allowAdd = urpDto.AllowAdd; allowEdit = urpDto.AllowEdit; allowDelete = urpDto.AllowDelete; allowPrint = urpDto.AllowPrint; allowView = urpDto.AllowView; } roleModelList.Add(new RoleModel { RolePermissionId = ++RolePermissionId, PermissionForRole = role, AllowAdd = allowAdd, AllowEdit = allowEdit, AllowDelete = allowDelete, AllowPrint = allowPrint, AllowView = allowView }); } Session[roleGroup + userGroupid] = roleModelList; } else { roleModelList = (List <RoleModel>)Session[roleGroup + userGroupid]; } return(roleModelList); }
public ActionResult SaveUserGroupRolePermissions(UserGroupRolesModel model) { UserGroupServiceReference.UserGroupServiceClient UGClient = null; UserGroupDto userGroupDto = new UserGroupDto(); string[] RoleGroupNames = { string.Empty }; int usergroupid = 0; if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"])) { usergroupid = Convert.ToInt32(Request.QueryString["usergroupid"]); } try { UGClient = new UserGroupServiceClient(); userGroupDto = UGClient.GetById(usergroupid); RoleGroupNames = (string[])Session["RoleGroupNames" + Request.QueryString["usergroupid"]]; //if (userGroupDto.RolePermissionsInUserGroup == null || userGroupDto.RolePermissionsInUserGroup.Count == 0) userGroupDto.RolePermissionsInUserGroup = new List <UserGroupRolePermissionDto>(); userGroupDto.RolePermissionsInUserGroup.Clear(); for (int i = 0; i < RoleGroupNames.Count(); i++) { List <RoleModel> Roles = (List <RoleModel>)Session[RoleGroupNames[i]]; if (Roles != null) { foreach (RoleModel rolemodel in Roles) { if (rolemodel.AllowAdd || rolemodel.AllowEdit || rolemodel.AllowPrint || rolemodel.AllowView || rolemodel.AllowDelete) { var userGroupRolePermissionDto = new UserGroupRolePermissionDto { PermissionForUserGroup = new List <UserGroupDto> { new UserGroupDto { UserGroupId = userGroupDto.UserGroupId } }, PermissionForRole = rolemodel.PermissionForRole, AllowAdd = rolemodel.AllowAdd, AllowEdit = rolemodel.AllowEdit, AllowView = rolemodel.AllowView, AllowDelete = rolemodel.AllowDelete, AllowPrint = rolemodel.AllowPrint }; userGroupDto.RolePermissionsInUserGroup.Add(userGroupRolePermissionDto); } } } } UGClient.Update(userGroupDto, ((UserDto)Session[Constants.SKCURRENTUSER]).UserName); UGClient.Close(); } catch (Exception ex) { return(View("ErrorPage")); } finally { if (RoleGroupNames != null && RoleGroupNames.Count() > 0) { for (int i = 0; i < RoleGroupNames.Count(); i++) { Session.Remove(RoleGroupNames[i]); } } if (Session["RoleGroupNames" + usergroupid] != null) { Session.Remove("RoleGroupNames" + usergroupid); } } return(RedirectToAction("UserGroupsIndex", new { usertype = Request.QueryString["usertype"] })); }