Example #1
0
        public void deleteUserRole(int id)
        {
            DBHelper._UserRole dbhelp_userRole  = new DBHelper._UserRole();
            UserRole           existingUserRole = dbhelp_userRole.GetByid(id);

            dbhelp_userRole.Delete(existingUserRole);

            DBHelper._EmployeeInRole dbhelp_employeeInRole = new DBHelper._EmployeeInRole();

            List <EmployeeInRole> employeeInRoleList = dbhelp_employeeInRole.GetAllByUserRoleId(id);

            dbhelp_employeeInRole.Delete(employeeInRoleList);
        }
Example #2
0
        public void updateUserRole(int id, Edit userRole)
        {
            DBHelper._UserRole dbhelp_useRole   = new DBHelper._UserRole();
            UserRole           existingUserRole = dbhelp_useRole.GetByid(id);

            existingUserRole.Name      = userRole.Name;
            existingUserRole.CompanyId = userRole.CompanyId;

            dbhelp_useRole.Update(existingUserRole);

            DBHelper._UserRolePermission dbhelp_useRolePermission = new DBHelper._UserRolePermission();
            List <UserRolePermission>    existingPermissionList   = dbhelp_useRolePermission.GetAllByUserRoleIdIncludeDelete(id);
            List <UserRolePermission>    insertPermissionList     = new List <UserRolePermission>();
            List <int> existingPermissionIdList = new List <int>();

            if (existingPermissionList.Count > 0)
            {
                foreach (var eurp in existingPermissionList)
                {
                    if (userRole.PermissionCatalogId == null || (!userRole.PermissionCatalogId.Contains(eurp.PermissionCatalogID) && !eurp.DeletedFlag))
                    {
                        eurp.DeletedFlag = true;
                    }
                    else if (userRole.PermissionCatalogId.Contains(eurp.PermissionCatalogID) && eurp.DeletedFlag)
                    {
                        eurp.DeletedFlag = false;
                    }
                    existingPermissionIdList.Add(eurp.PermissionCatalogID);
                }
                dbhelp_useRolePermission.UpdateManyRows(existingPermissionList);
            }


            if (userRole.PermissionCatalogId != null)
            {
                foreach (var permissionCatalogId in userRole.PermissionCatalogId)
                {
                    if (existingPermissionList.Count == 0 || (permissionCatalogId > 0 && !existingPermissionIdList.Contains(permissionCatalogId)))
                    {
                        var newUserRolePermissio = new UserRolePermission()
                        {
                            UserRoleID          = id,
                            PermissionCatalogID = permissionCatalogId
                        };
                        insertPermissionList.Add(newUserRolePermissio);
                    }
                }
                dbhelp_useRolePermission.AddManyRows(insertPermissionList);
            }
        }
Example #3
0
        public Detail getUserRoleById(int id)
        {
            DBHelper._UserRole       dbhelp_userRole          = new DBHelper._UserRole();
            UserRolePermissionModels userRolePermissionModels = new UserRolePermissionModels();
            UserRole userRole = dbhelp_userRole.GetByid(id);

            return(new Detail()
            {
                Id = userRole.Id,
                Name = userRole.Name,
                PermissionCatalogList = userRolePermissionModels.GetAllUserRolePermissionByUserRoleId(id).Select(s => new UserRolePermissionCatalog()
                {
                    Id = s.PermissionCatalogId,
                    Name = s.PermissionCatalogName,
                    Description = s.PermissionDescription
                }).ToList <UserRolePermissionCatalog>()
            });
        }