public override UserGroupDto EntityToEntityDto(UserGroup entity) { UserGroupDto usergroupDto = Mapper.Map <UserGroup, UserGroupDto>(entity); if (entity != null) { #region Map UserGroupRolePermission usergroupDto.RolePermissionsInUserGroup.Clear(); if (entity.RolePermissionsInUserGroup != null) { foreach (UserGroupRolePermission ugRolePermission in entity.RolePermissionsInUserGroup) { UserGroupRolePermissionDto ugrpDto = new UserGroupRolePermissionDto(); ugrpDto = Mapper.Map <UserGroupRolePermission, UserGroupRolePermissionDto>(ugRolePermission); ugrpDto.PermissionForRole = Mapper.Map <Role, RoleDto>(ugRolePermission.PermissionForRole); usergroupDto.RolePermissionsInUserGroup.Add(ugrpDto); } } if (entity.UsersInUserGroup != null) { foreach (User user in entity.UsersInUserGroup) { UserDto userDto = new UserDto(); userDto = Mapper.Map <User, UserDto>(user); usergroupDto.UsersInUserGroup.Add(userDto); } } #endregion } return(usergroupDto); }
public virtual void CreateUserGroupWithRolePermissions() { var userGroupDto = new UserGroupDto { UserGroupName = "General Manager", Description = "General Manager Description", CAId = 0, IsActive = true, IsDeleted = false, AllowEdit = true, AllowDelete = true, CreatedBy = -1, ModifiedBy = -1 }; var ugRolePermissionDto = new UserGroupRolePermissionDto { AllowAdd = true, AllowDelete = true, AllowEdit = true, AllowPrint = true, AllowView = true }; RoleDto roleDto = this.RoleService.GetById(10); ugRolePermissionDto.PermissionForRole = roleDto; userGroupDto.RolePermissionsInUserGroup.Add(ugRolePermissionDto); this.UserGroupInstance = this.UserGroupService.Create(userGroupDto, CurrentUserInstance.UserName); Assert.IsFalse(this.UserGroupInstance.UserGroupId == 0, "User Group Id should have been updated"); Assert.AreEqual(this.UserGroupInstance.UserGroupName, userGroupDto.UserGroupName, "User Group Name are different"); }
public virtual void AssignRoletoUserGroup() { RoleDto roleDto = this.RoleService.GetById(9); UserGroupDto ugDto = this.UserGroupService.GetById(2); var ugrpDto = new UserGroupRolePermissionDto { PermissionForUserGroup = new List <UserGroupDto> { new UserGroupDto { UserGroupId = ugDto.UserGroupId } }, PermissionForRole = roleDto, AllowAdd = false, AllowEdit = false, AllowView = false, AllowPrint = false, AllowDelete = false }; ugDto.RolePermissionsInUserGroup.Clear(); ugDto.RolePermissionsInUserGroup.Add(ugrpDto); this.UserGroupInstance = this.UserGroupService.Update(ugDto, CurrentUserInstance.UserName); Assert.IsTrue(this.UserGroupInstance.RolePermissionsInUserGroup[0].UserGroupRolePermissionId != 0, "UserGroupRolePermissionId should have been updated"); }
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"] })); }