Exemplo n.º 1
0
        public User GetUserbyUserId(int i)
        {
            DataTable userTable = manager.UserBasicInfoByUserId(i);

            if (userTable.Rows.Count == 0)
            {
                return(null);
            }
            DataRow row  = userTable.Rows[0];
            User    user = new User();

            user.UserId     = Convert.ToInt32(row["UserId"]);
            user.UserName   = row["UserName"] == null ? "" : row["UserName"].ToString();
            user.EmpName    = row["EmployeeName"] == null ? "" : row["EmployeeName"].ToString();
            user.Password   = row["Password"] == null ? "" : row["Password"].ToString();
            user.Mobile     = row["Mobile"] == null ? "" : row["Mobile"].ToString();
            user.EmployeeId = row["EmployeeId"] == null ? "" : row["EmployeeId"].ToString();
            if (user.UserId == UserAdminId)
            {
                user.IsAdmin = true;
            }
            user.IsActive = row["IsActive"] == null ? false : (row["IsActive"].ToString() == "0" ? false : true);
            IList <int> roleIds = manager.GetAllRolesIdByUserID(user.UserId);

            foreach (int roleID in roleIds)
            {
                Role role = Roles.DefaultRoles.GetRoleByRoleId(roleID);
                user.AddRole(role);
            }
            DataTable userRolePermissions = manager.GetAllRolePermissionsByUserId(user.UserId);

            foreach (DataRow row1 in userRolePermissions.Rows)
            {
                int        roleId       = Convert.ToInt32(row1["roleId"]);
                Role       role         = Roles.DefaultRoles.GetRoleByRoleId(roleId);
                int        permissionId = Convert.ToInt32(row1["permissionId"]);
                Permission permission   = Permissions.GetPermissionById(permissionId);
                user.AddPermission(permission, role);
            }
            return(user);
        }